class ThreadDemo1
{
public static void main(String[] args)
{
TestThread tt = new TestThread();
new Thread(tt).start();//为什么还要new Thread(tt) 呢 直接 tt.start()不行吗? 下面不是已经实现了Runnable接口了吗
new Thread(tt).start();
new Thread(tt).start();
new Thread(tt).start();
}
}
class TestThread implements Runnable
{
int tickets = 100;
public void run()
{
while (true)
{
if(tickets>0)
sop(Thread.currentThread().getName()+"正在售的票是“+tickets--)
}
}
} |