本帖最后由 殷俊 于 2015-3-26 12:06 编辑
这个程序的问题是,ThreadTest继承了Thread,super("DemoThread");后,System.out.println("child thread..."+ThreadDemo.currentThread());这样打印子线程的名字和优先级以及组名,为什么子线程的组名还是main,而不是DemoThread
class ThreadDemo extends Thread
{
ThreadDemo()
{
super("DemoThread");
System.out.println("child thread..."+ThreadDemo.currentThread());
//System.out.println("child thread..."+this);
start();
}
public void run()
{
try
{
for(int x=0;x<10;x++)
System.out.println("child name..."+x);
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("child over");
}
System.out.println("......child exit......");
}
}
class ThreadTest extends Thread
{
public static void main(String[] args)
{
new ThreadDemo();
try
{
for(int y=0;y<10;y++)
System.out.println("main thread......."+y);
Thread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println("main over");
}
System.out.println("........main exit........");
}
}
如图
|
|