多线程,获取当前线程的对象。

时间:2020-07-21 00:58:31   收藏:0   阅读:56
public class Demo02 {
public static void main(String[] args) {

Test01();
new Thread(){
public void run(){
System.out.println(getName()+".......ccccccccccc");
}
}.start();
new Thread( new Runnable(){
public void run(){
//Thread.currentThread()获取当前正在执行的线程
System.out.println(Thread.currentThread().getName()+"dddddddddd");
}
}).start();
System.out.println(Thread.currentThread().getName());//获取主线程的名字
Thread.currentThread().setName("我是主线程");
System.out.println(Thread.currentThread().getName());//再次获取主线程的名字

}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!