- 代码1
- class Test extends Thread
- {
- private String name;
- Test(String name)
- {
- this.nam=name;
- }
- public void run()
- {
- for(int x=0;x<60;x++)
- {
- System.out.println(Thread.currentThread().getName()+"...run..."+x);
- }
- }
- }
-
- class ThreadTest
- {
- public static void main(String[] args)
- {
- Test t1=new Test("one");
- Test t2=new Test("two");
- t1.start();
- t2.start();
- }
- }
- 代码2
- class Test extends Thread
- {
-
- Test(String name)
- {
- super(name);
- }
- public void run()
- {
- for(int x=0;x<60;x++)
- {
- System.out.println(Thread.currentThread().getName()+"...run..."+x);
- }
- }
- }
-
- class ThreadTest
- {
- public static void main(String[] args)
- {
- Test t1=new Test("one");
- Test t2=new Test("two");
- t1.start();
- t2.start();
- }
- }
- 以上两行代码为什么获取到的线程名称不同呀?
复制代码
|
|