Skip to content

Commit b012578

Browse files
committed
线程开启
1 parent 2cbb926 commit b012578

17 files changed

Lines changed: 264 additions & 0 deletions

File tree

‎bin/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/thread_1/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
}

0 commit comments

Comments
 (0)