📄 jointhread.java
字号:
//p186
//联合线程
public class JoinThread
{
public static void main (String args[])
{
TestThread t= new TestThread();
Thread pp=new Thread(t);
pp.start();
int i=0;
while (true)
{
if(i==100)
{
try
{
pp.join();
}
catch (Exception e)
{
System.out.println(e.getMessage()) ;
}
}
System.out.println("main Thread"+i++);
}
}
}
class TestThread implements Runnable
{
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 + -