threadoperator.java

来自「一些常用的java程序,包括swing.net.io,matrix等」· Java 代码 · 共 58 行

JAVA
58
字号
package creaatThread;

public class ThreadOperator
{
	public static void CommonCreate()
	{
		Thread [] t = new Thread[6];
		
		for(int i = 0; i < 6; i++)
		{
			if( i % 2 == 0)
				t[i] = new CreatThreadExtend(i);
			else
				t[i] = new Thread(new CreatThreadImplement(i));
		}
		for(int i = 0; i < 6; i++)
		{
			t[i].start();
			if(i % 2 == 0 && t[i].isDaemon()) t[i].setDaemon(false); //if no isDeamon, may produce exception
			System.out.println("thread "+ i + " begin");
		}
		
		//t[3].setDaemon(true); //set t[5] as Daemon thread, there is Exception
	}
	
	public static void TestThreadGroup()
	{
	//	Thread ot = new Thread();
	//	Thread et = new Thread(); 
		Thread [] td = new Thread[6];
		ThreadGroup etg = new ThreadGroup("evenTd");
		ThreadGroup otg = new ThreadGroup("oldTd");
		
		
		for(int i = 0; i < 6; i++)
		{
			if(i % 2 == 0)
				{
					td[i] = new CreatThreadExtend(etg, "etg"+i);
					td[i].start();
				}
			else
				{
					td[i] = new Thread(otg,new CreatThreadImplement(i), "otg"+i);			
					td[i].start();
				}
		}
	}//main()
	
	public static void main(String [] args)
	{
		//CommonCreate();
		TestThreadGroup();
		
	}

}

⌨️ 快捷键说明

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