目录
public class TestThread2 { public static void main(String [] args){ Window window=new Window(); Thread thread1=new Thread(window,"窗口一"); Thread thread2=new Thread(window,"窗口二"); Thread thread3=new Thread(window,"窗口三"); thread1.start(); thread2.start(); thread3.start(); } } class Window implements Runnable{ int ticket=50; @Override public void run(){ while (true){ if(ticket > 0){ try { Thread.currentThread().sleep(100);//模拟卖票需要一定的时间 } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(Thread.currentThread().getName()+"售票,票号为:"+ticket--); }else { break; } } } }

