File tree Expand file tree Collapse file tree 9 files changed +141
-28
lines changed
src/main/java/com/chen/api/util/thread Expand file tree Collapse file tree 9 files changed +141
-28
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1- package com .chen .api .util .thread ;
1+ package com .chen .api .util .thread . introduce ;
22
33/**
4+ * 面试题
45 * @Author chenweijie
56 * @Date 2017/9/18 23:45
67 */
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .newRunnalble ;
2+
3+ /**
4+ * 直接new Runnable创建多线程
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:43 AM
8+ */
9+ public class NewRunnable {
10+
11+
12+ public static void main (String [] args ) {
13+
14+ Runnable runnable = new Runnable () {
15+ @ Override
16+ public void run () {
17+ System .out .println ("124" );
18+ }
19+ };
20+ new Thread (runnable ).start ();
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .runnableTest ;
2+
3+ /**
4+ * 测试实现Runnable接口实现多线程
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:37 AM
8+ */
9+ public class MyRunnable implements Runnable {
10+
11+ @ Override
12+ public void run () {
13+ System .out .println (Thread .currentThread ().getName () + "...running!" );
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .runnableTest ;
2+
3+ /**
4+ * 测试类
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:38 AM
8+ */
9+ public class MyRunnableTest {
10+
11+ public static void main (String [] args ) {
12+
13+ Runnable myRunnable = new MyRunnable ();
14+
15+ Thread t = new Thread (myRunnable , "指定threadName的线程" );
16+
17+ t .start ();
18+ System .out .println ("main 线程在运行.." );
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .threadTest ;
2+
3+ /**
4+ * 继承thread类的多线程
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:20 AM
8+ */
9+ public class MyThread extends Thread {
10+
11+ @ Override
12+ public void run () {
13+ Thread .currentThread ().setName ("MyThread线程.." );
14+ System .out .println (Thread .currentThread ().getName () + "正在运行.." );
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .threadTest ;
2+
3+ /**
4+ * 测试类
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:21 AM
8+ */
9+ public class MyThreadTest {
10+
11+ public static void main (String [] args ) {
12+
13+ MyThread myThread = new MyThread ();
14+ myThread .start ();
15+
16+ System .out .println ("运行结束!" );
17+ }
18+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .threadTest2 ;
2+
3+ /**
4+ * 测试执行start方法的顺序不代表代码的执行顺序
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:29 AM
8+ */
9+ public class MyThread2 extends Thread {
10+
11+ private int i ;
12+
13+ public MyThread2 (int i ) {
14+ super ();
15+ this .i = i ;
16+ }
17+
18+ @ Override
19+ public void run () {
20+ System .out .println (i );
21+ }
22+ }
Original file line number Diff line number Diff line change 1+ package com .chen .api .util .thread .study .chapter1 .threadTest2 ;
2+
3+ /**
4+ * 测试类
5+ *
6+ * @author chen weijie
7+ * @date 2018-04-08 1:32 AM
8+ */
9+ public class MyThread2Test {
10+
11+ public static void main (String [] args ) {
12+ MyThread2 t1 = new MyThread2 (1 );
13+ MyThread2 t2 = new MyThread2 (2 );
14+ MyThread2 t3 = new MyThread2 (3 );
15+ MyThread2 t4 = new MyThread2 (4 );
16+ MyThread2 t5 = new MyThread2 (5 );
17+ MyThread2 t6 = new MyThread2 (6 );
18+ t1 .start ();
19+ t2 .start ();
20+ t3 .start ();
21+ t4 .start ();
22+ t5 .start ();
23+ t6 .start ();
24+ }
25+ }
You can’t perform that action at this time.
0 commit comments