-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadDemo0.java
More file actions
27 lines (24 loc) · 706 Bytes
/
ThreadDemo0.java
File metadata and controls
27 lines (24 loc) · 706 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
package java_Threads;
public class ThreadDemo0 {
public static void main(String args[]) throws Exception {
new TestThread0().run();// 调用start方法来启动线程的run方法,是并行运行(多线程运行);
// 直接调用run方法,会变成串行执行;该代码块执行不玩,下面的代码是不会执行的
while (true) {
System.out.println("main thread is running");
Thread.sleep(10);
}
}
}
class TestThread0 {
public void run() {
while (true) {
System.out.println(" TestThread1 is running");
try {
Thread.sleep(1000); // 1000毫秒
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}