📄 threaddmtb.java
字号:
public class ThreadDmtb
{
public static void main (String args[])
{
TestThread t= new TestThread();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
new Thread(t).start();
//每个线程都卖出了不同的票
}
}
class TestThread implements Runnable
{
private int tickets=50;
public void run()
{
while(true)
{
if (tickets>0)
{
try
{
Thread.sleep(10);
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
System.out.println(Thread.currentThread().getName() +
"is saling tickets"+tickets--);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -