黑马程序员技术交流社区
标题:
多线程中获取线程名称的两种方式
[打印本页]
作者:
suichuan689
时间:
2015-9-2 09:01
标题:
多线程中获取线程名称的两种方式
class MyThread extends Thread{
public MyThread(String name) {
super(name);
}
public void run(){
for(int x=0;x<1000;x++){
System.out.println((this.currentThread()==this)+"+++"+this.getName()+"---"+x);
}
}
}
public class YiChang {
public static void main(String[] args) throws InterruptedException {
MyThread myThread=new MyThread("One");
myThread.setName("One1");
myThread.start();
for(int x=0;x<1000;x++){
System.out.println("main---"+x);
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2