package test;
import java.io.*;
public class Test
{
public static void main(String[] args)
{
Tickits t = new Tickits();
new Thread(t,"窗口1").start();
new Thread(t,"窗口2").start();
}
}
class Tickits implements Runnable
{
int num;
Tickits()
{
num = 10;
}
public void run()
{
while (true)
{
synchronized (this)
{
if (num > 0)
{
try
{
Thread.sleep(1000);
} catch (InterruptedException ex)
{
ex.printStackTrace();
}
System.out.println(Thread.currentThread().getName() +
" selling tickit" + num);
num--;
} else
break;
}
}
}
}
JAVA线程实例-----卖票
最新推荐文章于 2025-02-16 00:25:22 发布