From 1ecd8f82f3a1af882da9ded77152174fe44cb846 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 21:58:02 +0800 Subject: [PATCH 1/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java index b3c357b..af7ec30 100644 --- a/Chapter11/Creating_a_Thread.java +++ b/Chapter11/Creating_a_Thread.java @@ -23,7 +23,7 @@ public void run() { // Threads start executing here. } catch (InterruptedException exc) { System.out.println(thrdName + " interrupted."); } - + System.out.println(thrdName + " terminating."); } } From 7fe9c1d0e4fabe2ba1400fc32511bc99fa78cdaa Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:01:56 +0800 Subject: [PATCH 2/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java index af7ec30..5f5ac2e 100644 --- a/Chapter11/Creating_a_Thread.java +++ b/Chapter11/Creating_a_Thread.java @@ -33,6 +33,11 @@ public class Creating_a_Thread { public static void main(String[] args) { // TODO Auto-generated method stub + + System.out.println("Main thread starting."); + + // First, construct a MyThread object. + MyThread2023 myThread2023 = new MyThread2023("Child #1"); // Create a runnable object. } From 11b7a852a3747fd0eeb5a06b356bc530201fdffe Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:06:57 +0800 Subject: [PATCH 3/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java index 5f5ac2e..e1971f3 100644 --- a/Chapter11/Creating_a_Thread.java +++ b/Chapter11/Creating_a_Thread.java @@ -38,6 +38,9 @@ public static void main(String[] args) { // First, construct a MyThread object. MyThread2023 myThread2023 = new MyThread2023("Child #1"); // Create a runnable object. + + // Next, construct a thread from that object. + Thread newThread = new Thread(myThread2023); // Construct a thread on that object. } From 36be41ee88b9964ce9b3e8a4cf414131c18717ef Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:08:19 +0800 Subject: [PATCH 4/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java index e1971f3..a95f146 100644 --- a/Chapter11/Creating_a_Thread.java +++ b/Chapter11/Creating_a_Thread.java @@ -41,6 +41,9 @@ public static void main(String[] args) { // Next, construct a thread from that object. Thread newThread = new Thread(myThread2023); // Construct a thread on that object. + + // Finally, start execution of the thread. + newThread.start(); // Start running the thread. } From 2264dc40b102e5268d72b95f6768f9dc917045a5 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 22:11:11 +0800 Subject: [PATCH 5/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Chapter11/Creating_a_Thread.java b/Chapter11/Creating_a_Thread.java index a95f146..adb6735 100644 --- a/Chapter11/Creating_a_Thread.java +++ b/Chapter11/Creating_a_Thread.java @@ -44,6 +44,17 @@ public static void main(String[] args) { // Finally, start execution of the thread. newThread.start(); // Start running the thread. + + for (int i = 0; i < 50; i++) { + System.out.print("."); + try { + Thread.sleep(100); + } catch (InterruptedException exc) { + System.out.println("Main thread interrupted."); + } + } + + System.out.println("Main thread ending."); } From 38244444c87b51feab3a0fb7db7023a5d9e5bcb3 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:48:47 +0800 Subject: [PATCH 6/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread_annotated.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Chapter11/Creating_a_Thread_annotated.java diff --git a/Chapter11/Creating_a_Thread_annotated.java b/Chapter11/Creating_a_Thread_annotated.java new file mode 100644 index 0000000..407e3a6 --- /dev/null +++ b/Chapter11/Creating_a_Thread_annotated.java @@ -0,0 +1,21 @@ +// To create a new thread, your program will either extend Thread or implement the Runnable interface. +class MyThread202310 implements Runnable{ + + public void run() { + + + } + +} + + +public class Creating_a_Thread_annotated { + + // From the main thread, you can create other threads. + public static void main(String[] args) { + + System.out.println("Main thread starting."); + + } + +} From 29e89cea550f3c12f1049b26cf407ae85cf3c110 Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:53:18 +0800 Subject: [PATCH 7/8] Committed on or aroound 2023/10/05 --- Chapter11/Creating_a_Thread_annotated.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Chapter11/Creating_a_Thread_annotated.java b/Chapter11/Creating_a_Thread_annotated.java index 407e3a6..00e1b20 100644 --- a/Chapter11/Creating_a_Thread_annotated.java +++ b/Chapter11/Creating_a_Thread_annotated.java @@ -13,8 +13,9 @@ public class Creating_a_Thread_annotated { // From the main thread, you can create other threads. public static void main(String[] args) { - System.out.println("Main thread starting."); + + // To create another thread from within the main thread, construct a MyThread object first. } From 7497255e4d81b8a17445cddda5afe72ee651542e Mon Sep 17 00:00:00 2001 From: Ceiling_roof <48134466+ResilientSpring@users.noreply.github.com> Date: Thu, 5 Oct 2023 23:59:08 +0800 Subject: [PATCH 8/8] Committed on or around 2023/10/05 --- Chapter11/Creating_a_Thread_annotated.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Chapter11/Creating_a_Thread_annotated.java b/Chapter11/Creating_a_Thread_annotated.java index 00e1b20..abe09f2 100644 --- a/Chapter11/Creating_a_Thread_annotated.java +++ b/Chapter11/Creating_a_Thread_annotated.java @@ -16,6 +16,7 @@ public static void main(String[] args) { System.out.println("Main thread starting."); // To create another thread from within the main thread, construct a MyThread object first. + }