-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJoinTest.java
More file actions
56 lines (48 loc) · 1.42 KB
/
Copy pathJoinTest.java
File metadata and controls
56 lines (48 loc) · 1.42 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Thread;
//线程实例的join()方法可以使得一个线程在另一个线程结束后再执行,即也就是说使得当前线程可以阻塞其他线程执行;
//结论是:t1阻塞t2和t3,t2和t3是乱序的
public class JoinTest
{
public static void main(String[] args) throws InterruptedException
{
Thread t1 = new Thread(new Runnable()
{
@Override
public void run()
{
System.out.println("start t1 task...");
try
{
Thread.sleep(2000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
System.out.println("start t1 task...");
System.out.println("end t1 task...");
}
});
Thread t2 = new Thread(new Runnable()
{
@Override
public void run()
{
System.out.println("end t2 task...");
System.out.println("start t2 task...");
}
});
Thread t3 = new Thread(new Runnable()
{
@Override
public void run()
{
System.out.println("end t3 task...");
System.out.println("start t3 task...");
}
});
t1.start();
t1.join();
t2.start();
t3.start();
}
}