testsubthread2.java

来自「TestMyClassThread.javaJAVA一线程源码」· Java 代码 · 共 50 行

JAVA
50
字号
package Thread;

public class TestSubThread2
{
	public static void main(String []args) throws InterruptedException
	{
		SubThread t1=new SubThread("First     ");
		SubThread t2=new SubThread("Second    ");
		SubThread t3=new SubThread("Third     ");
		t1.start();
                //Thread.sleep(500);
		try
		{
			t1.join();
		}
		catch(InterruptedException e)
		{
			System.out.println(e.toString());
		}
		t2.start();
		t3.start();		
		System.out.println("    叱痰    t1    校    main()    希");
	}
}
class SubThread extends Thread
{
	String str;
	public SubThread(String s)
	{
		super(s);
	}
	public void run()
	{
		for(int i=1;i<8;i++)
		{
			try
			{
				sleep((int)(Math.random()*100));
			}
			catch(InterruptedException e)
			{
				System.out.println(e.toString());
			}
			//for(long j=1;j<100000000;j++);
			System.out.println(getName()+"    "+i+"    !");
		}
		System.out.println(getName()+"    end:    !");
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?