多線程,獲取當前線程的對象。


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());//再次獲取主線程的名字

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM