-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWindow1.java
More file actions
39 lines (38 loc) · 1010 Bytes
/
Window1.java
File metadata and controls
39 lines (38 loc) · 1010 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
34
35
36
37
38
39
package org.cp;
/**
* 继承方式线程
* 线程不安全 原版
* create by CP on 2019/7/25 0025.
*/
public class Window1 extends Thread {
private static int ticket = 100;
@Override
public void run() {
while (true) {
if (ticket>0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+ ": "+ticket);
ticket--;
} else {
break;
}
}
}
}
class WindowTest1 {
public static void main(String[] args) {
Window1 window1 = new Window1();
Window1 window2 = new Window1();
Window1 window3 = new Window1();
window1.setName("窗口1 ");
window2.setName("窗口2 ");
window3.setName("窗口3 ");
window1.start();
window2.start();
window3.start();
}
}