Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ThreadName from ThreadID

Is there a way to get a Thread's ThreadName from a ThreadId? (from say, a ThreadID like 10, or 15, etc.)

like image 256
littleduckie Avatar asked Apr 14 '09 17:04

littleduckie


People also ask

How do you get thread out of a Threadpool?

There is the way of current thread getting: Thread t = Thread. currentThread(); After you have got Thread class object (t) you are able to get information you need using Thread class methods.

How do I get the current thread name?

In the run() method, we use the currentThread(). getName() method to get the name of the current thread that has invoked the run() method. We use the currentThread(). getId() method to get the id of the current thread that has invoked the run() method.

How do you get the current thread in Python?

In Python 3.3+, you can use threading. get_ident() function to obtain the thread ID of a thread. threading. get_ident() returns the thread ID of the current thread.

What is a thread ID?

Thread Id is a long positive integer that is created when the thread was created. During the entire lifecycle of a thread, the thread ID is unique and remains unchanged. It can be reused when the thread is terminated.


2 Answers

Not in managed code. You can't even get a list of Thread objects for the current process, as far as I'm aware. You can get the ProcessThreads with Process.Threads and ProcessThread provides an Id property, if that helps you... but a ProcessThread doesn't have a name as far as I can tell :(

like image 98
Jon Skeet Avatar answered Oct 26 '22 00:10

Jon Skeet


The best information that I could find is here:

http://www.mail-archive.com/[email protected]/msg07369.html

That doesn't seem too helpful, though. It seems that there is no good way to do this, short of you changing the code to maintain a list (or dictionary) of all of your application's threads.

like image 22
jsight Avatar answered Oct 25 '22 22:10

jsight