File tree Expand file tree Collapse file tree
src/org/javacore/thread/join Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments