设置和获取 线程名称
- currentThread
- getName
- setName
package xc;
public class Demo3 {
/**
* currentThread:获取当前正在执行的线程对象
* getName:获取当前正在执行的线程名称
* setName:修改名称
*/
public static void main(String[] args) {
System.out.println(Thread.currentThread().getName());
MyRunnable m = new MyRunnable();
Thread t = new Thread(m);
t.setName("hhh");
t.start();
new Thread(new MyRunnable()).start();
new Thread(new MyRunnable()).start();
}
static class MyRunnable implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
}