Three kinds of naming Java threads

1. Examples of a thread object

1 Thread t = new Thread();
2 t.setName("甲");

2. Examples of a thread object simultaneously, named by the thread constructor

1 Thread(Runnable r, String name)
2 Thread t = new Thread(() -> {}, "甲");

3. custom thread class, instantiated thread object, while the name of the assignment

 1 MyThread t = new MyThread("甲");
 2 
 3 class MyThread extends Thread{
 4     
 5     public MutliTread(String name) {
 6         this.setName(name);
 7         //super(name)
 8     }
 9     public void run() {...}
10 }

 

Guess you like

Origin www.cnblogs.com/ggrrbb/p/12289693.html