/*
例子:创建三个窗口卖票,总共100张
/
package com.atguigu.java1;
/**
*例子:创建三个窗口卖票,总共100张
*存在线程安全问题,待解决
*
* @author Dxkstart
* @create 2021-05-06 16:46
*/
public class WindowTest {
public static void main(String[] args) {
Window w1 = new Window();
Window w2 = new Window();
Window w3 = new Window();
w1.start();
w2.start();
w3.start();
}
}
class Window extends Thread {
private static int ticket = 100;//票数
@Override
public void run() {
while(true){
if(ticket > 0){
System.out.println(getName() + ": 卖票,票号为" + ticket);
ticket --;
}else{
break;
}
}
}
}