jointhread.java
来自「用java编写的一些初级代码」· Java 代码 · 共 42 行
JAVA
42 行
//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 + =
减小字号Ctrl + -
显示快捷键?