Detailed explanation of three naming methods of Java thread
This article introduces the relevant knowledge of "detailed explanation of three naming methods of Java threads". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Instantiate a thread object
Thread t = new Thread (); t.setName (A)
two。 While instantiating a thread object, the thread is named by the construction method.
Thread (Runnable r, String name) Thread t = new Thread (()-> {}, "A")
3. Using a custom thread class, assign the name while instantiating the thread object
MyThread t = new MyThread ("A"); class MyThread extends Thread {public MutliTread (String name) {this.setName (name); / / super (name)} public void run () {...}}
This is the end of the content of "detailed explanation of three naming methods for Java threads". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!