-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestwait.java
More file actions
30 lines (27 loc) · 845 Bytes
/
Testwait.java
File metadata and controls
30 lines (27 loc) · 845 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
29
30
package win.sz90.threadwait;
import java.util.concurrent.TimeUnit;
public class Testwait implements Runnable{
public static void main(String[] args) {
Testwait testwait = new Testwait();
Thread thread1 = new Thread(testwait,"thread1 ");
Thread thread2 = new Thread(testwait,"thread2 ");
thread1.start();
thread2.start();
}
@Override
public void run() {
synchronized (this){
System.out.println(Thread.currentThread().getName()+"正在运行");
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}