public class ThreadTest获取当前线程对象 {
public static void main(String[] args) {
Thread tt1 = Thread.currentThread();
System.out.println(tt1.getName());//main
test t1 = new test();
t1.setName("t1");
t1.start();
test t2 = new test();
t2.setName("t2");
t2.start();
}
}
class test extends Thread{
@Override
public void run() {
//获取当前线程的对象,这个方法在哪,就代表对应的对象
Thread t1 = Thread.currentThread();
System.out.println(t1.getName());
}
}
多线程的获取线程对象
最新推荐文章于 2022-11-23 23:44:47 发布