How to set name to the thread?
Check the Thread
constructors, there are a few with a String name
parameter. Or you can call setName(String)
on an existing Thread.
You can easily pass a thread name in Its Constructor, like:
Thread foo = new Thread("Foo");
... or by calling Thread#setName
:
public final void setName (String threadName)
Sets the name of the Thread.
as thread.setName("Thread-11");
or like Thread.currentThread().setName("Thread-11");