- Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestThread.java
More file actions
Latest commit
42 lines (36 loc) · 1.11 KB
/
Copy pathTestThread.java
File metadata and controls
42 lines (36 loc) · 1.11 KB
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
classThreadDemoextendsThread {
privateThreadt;
privateStringthreadName;
ThreadDemo( Stringname) {
threadName = name;
System.out.println("Creating " + threadName );
}
publicvoidrun() {
System.out.println("Running " + threadName );
try {
for(inti = 4; i > 0; i--) {
System.out.println("Thread: " + threadName + ", " + i);
// Let the thread sleep for a while.
Thread.sleep(50);
}
} catch (InterruptedExceptione) {
System.out.println("Thread " + threadName + " interrupted.");
}
System.out.println("Thread " + threadName + " exiting.");
}
publicvoidstart () {
System.out.println("Starting " + threadName );
if (t == null) {
t = newThread (this, threadName);
t.start ();
}
}
}
publicclassTestThread {
publicstaticvoidmain(Stringargs[]) {
ThreadDemoT1 = newThreadDemo( "Thread-1");
T1.start();
ThreadDemoT2 = newThreadDemo( "Thread-2");
T2.start();
}
}