File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /thread_1 /
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_1_t1 ;
2+
3+ public class MyThread extends Thread {
4+
5+ @ Override
6+ public void run () {
7+ super .run ();
8+ System .out .println ("MyThread" );
9+ }
10+
11+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_1_t1 ;
2+
3+ public class Run {
4+
5+ public static void main (String [] args ) {
6+ MyThread myThread = new MyThread ();
7+ myThread .start ();
8+ System .out .println ("运行结束!" );
9+ }
10+
11+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_2_rundomThread ;
2+
3+ public class MyThread extends Thread {
4+
5+ @ Override
6+ public void run () {
7+ try {
8+ for (int i = 0 ; i < 10 ; i ++) {
9+ int time = (int ) (Math .random () * 1000 );
10+ Thread .sleep (time );
11+ System .out .println ("run=" + Thread .currentThread ().getName ());
12+ }
13+ } catch (InterruptedException e ) {
14+ e .printStackTrace ();
15+ }
16+ }
17+
18+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_2_rundomThread ;
2+
3+ public class Test {
4+
5+ public static void main (String [] args ) {
6+ try {
7+
8+ MyThread thread = new MyThread ();
9+ thread .setName ("myThread" );
10+ thread .start ();
11+
12+ for (int i = 0 ; i < 10 ; i ++) {
13+ int time = (int ) (Math .random () * 1000 );
14+ Thread .sleep (time );
15+ System .out .println ("main=" + Thread .currentThread ().getName ());
16+ }
17+ } catch (InterruptedException e ) {
18+ e .printStackTrace ();
19+ }
20+ }
21+
22+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_3_z ;
2+
3+ public class MyThread extends Thread {
4+
5+ private int i ;
6+
7+ public MyThread (int i ) {
8+ super ();
9+ this .i = i ;
10+ }
11+
12+ @ Override
13+ public void run () {
14+ System .out .println (i );
15+ }
16+
17+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_1 .project_3_z ;
2+
3+ public class Test {
4+
5+ public static void main (String [] args ) {
6+ MyThread t11 = new MyThread (1 );
7+ MyThread t12 = new MyThread (2 );
8+ MyThread t13 = new MyThread (3 );
9+ MyThread t14 = new MyThread (4 );
10+ MyThread t15 = new MyThread (5 );
11+ MyThread t16 = new MyThread (6 );
12+ MyThread t17 = new MyThread (7 );
13+ MyThread t18 = new MyThread (8 );
14+ MyThread t19 = new MyThread (9 );
15+ MyThread t110 = new MyThread (10 );
16+ MyThread t111 = new MyThread (11 );
17+ MyThread t112 = new MyThread (12 );
18+ MyThread t113 = new MyThread (13 );
19+
20+ t11 .start ();
21+ t12 .start ();
22+ t13 .start ();
23+ t14 .start ();
24+ t15 .start ();
25+ t16 .start ();
26+ t17 .start ();
27+ t18 .start ();
28+ t19 .start ();
29+ t110 .start ();
30+ t111 .start ();
31+ t112 .start ();
32+ t113 .start ();
33+
34+ }
35+
36+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_2 .project_2_t2 ;
2+
3+ public class MyRunnable implements Runnable {
4+
5+ @ Override
6+ public void run () {
7+ System .out .println ("н╦ллол!" );
8+ }
9+
10+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_2 .project_2_t2 ;
2+
3+ public class Run {
4+
5+ public static void main (String [] args ) {
6+ Runnable runnable =new MyRunnable ();
7+ Thread thread =new Thread (runnable );
8+ thread .start ();
9+ System .out .println ("运行结束!" );
10+ }
11+
12+ }
Original file line number Diff line number Diff line change 1+ package thread_1 .thread_1_2 .thread_1_2_2 .project_2_t3 ;
2+
3+ public class MyThread extends Thread {
4+
5+ private int count = 5 ;
6+
7+ public MyThread (String name ) {
8+ super ();
9+ this .setName (name );
10+ }
11+
12+ @ Override
13+ public void run () {
14+ super .run ();
15+ while (count > 0 ) {
16+ count --;
17+ System .out .println ("由 " + this .currentThread ().getName ()
18+ + " 计算,count=" + count );
19+ }
20+ }
21+ }
You can’t perform that action at this time.
0 commit comments