public class Thread2 extends Thread
{ public Thread2(ThreadGroup tg,String name)
{ super(tg,name);
}
public void run()
{ try
{ System.out.print(getName()+" sleep ");
this.sleep(1000); //睡眠一秒钟
}
catch(InterruptedException e)
{ System.out.println(e.getMessage());
}
System.out.print(getName() +" end! ");
}
public static void main (String args[])
{
ThreadGroup tg1 = new ThreadGroup("tg1"); //创建一个线程组
new Thread2(tg1,"A").start();
new Thread2(tg1,"B").start();
ThreadGroup tg2 = new ThreadGroup("tg2");
new Thread2(tg2,"C").start();
new Thread2(tg2,"D").start();
Thread curt = Thread.currentThread(); //返回当前活动线程
System.out.println("currentThread="+curt.getName());
System.out.println("getPriority = "+curt.getPriority());//优先级
System.out.println("activeCount="+Thread.activeCount());
Thread ta[]=new Thread[10];
Thread.enumerate(ta); //将当前活动线程复制到ta数组中
System.out.println("Group_Name isAlive()");
for (int i=0;i<Thread.activeCount();i++)
System.out.println(ta[i].getThreadGroup().getName()
+"_"+ta[i].getName()+" "+ta[i].isAlive());
}
}