package cn.itcast_02;
public class Runnerable接口实现买票 {
public static void main(String[] args) {
MyRunnable my = new MyRunnable();
Thread t1 = new Thread(my,"窗口1");
Thread t2 = new Thread(my,"窗口2");
Thread t3 = new Thread(my,"窗口3");
t1.start();
t2.start();
t3.start();
}
}
package cn.itcast_02;
public class MyRunnable implements Runnable {
private static int ticked = 100;
@Override
public void run() {
while(true) {
if(ticked>0) {
System.out.println(Thread.currentThread().getName()+"正在出售第"+(ticked--)+"票");
}
}
}
}