Skip to content

Commit 2bd5241

Browse files
author
bysocket
committed
join方法的使用
1 parent faeebac commit 2bd5241

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.javacore.thread.join;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
/**
6+
* Created by bysocket on 16/3/3.
7+
*/
8+
public class DSLoader implements Runnable {
9+
@Override
10+
public void run() {
11+
System.out.println("begining the DSLoader");
12+
try {
13+
TimeUnit.SECONDS.sleep(4);
14+
} catch (InterruptedException e) {
15+
e.printStackTrace();
16+
}
17+
System.out.println("DSLoader has finished");
18+
}
19+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.javacore.thread.join;
2+
3+
/**
4+
* Created by bysocket on 16/3/3.
5+
*/
6+
public class JoinTest {
7+
public static void main(String[] args) throws InterruptedException {
8+
Thread t1 = new Thread(new DSLoader());
9+
Thread t2 = new Thread(new NetLoader());
10+
11+
t1.start();
12+
t2.start();
13+
14+
//可以注释其中一个加深理解
15+
t1.join();
16+
t2.join();
17+
18+
System.out.println("ending all");
19+
}
20+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.javacore.thread.join;
2+
3+
import java.util.concurrent.TimeUnit;
4+
5+
/**
6+
* Created by bysocket on 16/3/3.
7+
*/
8+
public class NetLoader implements Runnable {
9+
@Override
10+
public void run() {
11+
System.out.println("begining the NetLoader");
12+
try {
13+
TimeUnit.SECONDS.sleep(6);
14+
} catch (InterruptedException e) {
15+
e.printStackTrace();
16+
}
17+
System.out.println("NetLoader has finished");
18+
}
19+
}

0 commit comments

Comments
 (0)