-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyThread1.java
More file actions
33 lines (29 loc) · 809 Bytes
/
MyThread1.java
File metadata and controls
33 lines (29 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package ThreadDemo;
/**
* @author:Gerry
* @description:多个线程之间不共享变量线程安全的情况
* @date: Created in 2018/12/21
*/
public class MyThread1 extends Thread {
private int count = 5;
public MyThread1(String name) {
super();
this.setName(name);
}
@Override
public void run() {
super.run();
while (count > 0) {
count--;
System.out.println("由 " + MyThread1.currentThread().getName() + " 计算,count=" + count);
}
}
public static void main(String[] args) {
MyThread1 thread1 = new MyThread1("A");
MyThread1 thread2 = new MyThread1("B");
MyThread1 thread3 = new MyThread1("C");
thread1.start();
thread2.start();
thread3.start();
}
}