package cn.text;
public class ThreadSell extends Thread{
public int ticks=100;
public ThreadSell(String str){
super(str);
}
public void run(){
while(ticks>0)
{
synchronized(this){
try
{
Thread.sleep(100);
sell();
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
public void sell(){
if(ticks>0)
{
System.out.println(Thread.currentThread().getName()+"卖出第"+ticks+"张票");
ticks--;
}
else return;
}
public static void main(String[] arge){
ThreadSell t =new ThreadSell("");
Thread t1 =new Thread(t,"窗口1");
Thread t2 =new Thread(t,"窗口2");
t1.start();
t2.start();
}
}