Prizoff Prizoff - 1 year ago 79
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'.


Answer Source

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");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download