📄 threaddm4.java
字号:
public class ThreadDm4
{
public static void main (String args[])
{
/*
TestThread t=new TestThread();
t.start();
t.start();
t.start();
t.start();
//无论调用多少次start,结果都只有一个线程
*/
new TestThread().start();
new TestThread().start();
new TestThread().start();
new TestThread().start();
//每个线程都卖出了各自的票
}
}
class TestThread extends Thread
{
private int tickets=50;
public void run()
{
while(true)
{
if (tickets>0)
System.out.println(Thread.currentThread().getName() +
"is saling tickets"+tickets--);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -