public class Dome {
public static void main(String[] args) {
//Thread.currentThread().getName() :获取当前运行的线程的名称
System.out.println(Thread.currentThread().getName());
new Thread(new MyRunnbale(),"线程名称").start();
new Thread(new MyRunnbale()).start();
new Thread(new MyRunnbale()).start();
new Thread(new MyRunnbale()).start();
}
static class MyRunnbale implements Runnable{
@Override
public void run() {
System.out.println(Thread.currentThread().getName());
}
}
}
运行结果:
main
线程名称
Thread-2
Thread-1
Thread-0