本帖最后由 Sofoul 于 2013-5-23 23:25 编辑
package thread;
public class TicketDemo implements Runnable{
private int ticket=100;
public void run(){
while(true){
if(ticket>0)
System.out.println(Thread.currentThread().getName()+"正在售出的是第"+(ticket--)+"张票");
}
}
}
package thread;
public class TicketDemoTest {
/**
* @param args
*/
public static void main(String[] args) {
TicketDemo t=new TicketDemo();
Thread s=new Thread(t,"窗口1");
Thread s1=new Thread(t,"窗口2");
Thread s2=new Thread(t,"窗口3");
s.start();
s1.start();
s2.start();
}
}
|