⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jointhread.java

📁 用java编写的一些初级代码
💻 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 + -