Prizoff Prizoff - 11 months ago 45
Java Question

How to set name to the thread?

Is there a way to set a friendly name to a thread in code?

For example, I want the thread with name Thread-11 on the image was named something like 'MyImportThread'.



You can easily pass a thread name in Its Constructor. or by calling below method

public final void setName (String threadName)

Sets the name of the Thread.

as thread.setName("Thread-11"); or like Thread.currentThread().setName("Thread-11");