Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set name to the thread?

Tags:

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'.

example-threads

like image 585
Prizoff Avatar asked Jul 12 '12 17:07

Prizoff


People also ask

How do you name a thread in Python?

The name for a new thread can be set via the “name” argument in the constructor to the threading. Thread class when creating a new thread.

How do you name a thread in C#?

In C#, a user is allowed to assign a name to the thread and also find the name of the current working thread by using the Thread.Name property of the Thread class. Here, the string contains the name of the thread or null if no name was assigned or set.

How do we set properties for thread?

Gets or sets the culture for the current thread. Gets or sets the thread's current principal (for role-based security). Gets the currently running thread. Gets or sets the current culture used by the Resource Manager to look up culture-specific resources at run-time.

How do you call a thread in Java?

The run() method of thread class is called if the thread was constructed using a separate Runnable object otherwise this method does nothing and returns. When the run() method calls, the code specified in the run() method is executed. You can call the run() method multiple times.


1 Answers

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

like image 112
AAnkit Avatar answered Sep 28 '22 04:09

AAnkit