版权声明:转载注明来源。Keep Learning and Coding. https://blog.csdn.net/a771581211/article/details/88667699
package day09;
/**
* static Thread currentThread()
* 获取运行当前方法的线程。
* @author kaixu
*
*/
public class ThreadDemo4 {
public static void main(String[] args) {
Thread main = Thread.currentThread();
System.out.println("主线程是:"+main);
dosome();
Thread t = new Thread(){
public void run() {
Thread t = Thread.currentThread();
System.out.println("自定线程:"+t);
dosome();
}
};
t.start();
}
public static void dosome(){
Thread t = Thread.currentThread();
System.out.println("运行dosome方法的线程:"+t);
}
}