package day04;
/**
* 线程提供了一个静态方法:
* static Thread currentThread()
* 该方法可以获取运行该方法的线程
* @author Administrator
*
*/
public class CurrentThreadDemo {
public static void main(String[] args) {
Thread main = Thread.currentThread();
System.out.println("运行main方法的线程是:"+main);
dosome();
Thread t = new Thread(){
public void run(){
Thread t = Thread.currentThread();
System.out.println("自定义线程:"+t);
dosome();
}
};
t.start();
}
private static void dosome() {
Thread t = Thread.currentThread();
System.out.println("运行dosome方法的线程是:"+t);
}
}
Java——static Thread currentThread()
最新推荐文章于 2024-07-27 23:50:11 发布