📄 threadoperator.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -