Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion 24 Chapter11/Creating_a_Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void run() { // Threads start executing here.
} catch (InterruptedException exc) {
System.out.println(thrdName + " interrupted.");
}

System.out.println(thrdName + " terminating.");
}

}
Expand All @@ -33,6 +33,28 @@ 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.

// 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.

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.");

}

Expand Down
23 changes: 23 additions & 0 deletions 23 Chapter11/Creating_a_Thread_annotated.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.");

// To create another thread from within the main thread, construct a MyThread object first.


}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.