package cn.itcast_01;
public class Thread类实现买电影案例 {
public static void main(String[] args) {
MyThread my1 = new MyThread();
MyThread my2 = new MyThread();
MyThread my3 = new MyThread();
my1.setName("窗口1");
my2.setName("窗口2");
my3.setName("窗口3");
my1.start();
my2.start();
my3.start();
}
}
package cn.itcast_01;
public class MyThread extends Thread{
private static int ticket = 100;
public void run() {
while(true)
if(ticket>0) {
System.out.println(getName() + "正在出售"+(ticket--)+"张票");
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-17323.html