-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadDemo2.java
More file actions
28 lines (26 loc) · 652 Bytes
/
ThreadDemo2.java
File metadata and controls
28 lines (26 loc) · 652 Bytes
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
package java_Threads;
public class ThreadDemo2 {
public static void main(String args[]) throws InterruptedException {
// main函数可能早于子线程结束;
// main线程和子线程都结束了,整个程序才算终止;
new TestThread2().start();
// while(true)
// {
// System.out.println("main thread is running");
// Thread.sleep(1000);
// }
}
}
class TestThread2 extends Thread {
public void run() {
while (true) {
System.out.println("TestThread2" + " is running");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}