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

Latest commit

 

History

History
History
51 lines (44 loc) · 1009 Bytes

File metadata and controls

51 lines (44 loc) · 1009 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Project 11-1
Extend Thread.
*/
class MyThread extends Thread {
int count;
// Construct a new thread.
MyThread(String name) {
super(name);
count = 0;
start(); // start the thread
}
// Begin execution of new thread.
public void run() {
System.out.println(getName() + " starting.");
try {
do {
Thread.sleep(100);
System.out.println("In " + getName() + ", count is " + count);
count++;
} while(count < 10);
}
catch(InterruptedException exc) {
System.out.println(getName() + " interrupted.");
}
System.out.println(getName() + " terminating.");
}
}
class UseThreadsImproved {
public static void main(String args[]) {
System.out.println("Main thread starting.");
MyThread mt = new MyThread("Child #1");
do {
System.out.print(".");
try {
Thread.sleep(10);
}
catch(InterruptedException exc) {
System.out.println("Main thread interrupted.");
}
} while (mt.count != 10);
System.out.println("Main thread ending.");
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.