Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread names--when do you need to know them?

I created a SO question about naming conventions for threads a while ago. The question was something like, "How should you name a thread?"

Looking back, a thread name only matters if you have to read a thread's name.

Can you provide real-world examples of when you've had to examine threads and discern between them, relying on their names? This is platform/framework agnostic.

How (in what environment), did you do this?

Put another way, in what scenarios have you had to solve a problem and had to examine threads by name, and how did you accomplish this?

like image 473
core Avatar asked Apr 18 '09 06:04

core


2 Answers

When looking for connection leaks in java, it is sometimes useful to trace an object back to see which thread it was created by. In our case, it was the Finalizer thread. This led us to the conclusion that things were getting garbage collected, but not being Finalized fast enough. i.e. a bunch of stuff was waiting to be finalized, which was all done in one thread.

As a result, we learnt a lesson about not relying on Finalize.

like image 56
WW. Avatar answered Oct 22 '22 05:10

WW.


This question is currently tagged with 'linux' for no apparent reason... anyway, if you're using Visual Studio, the thread name appears in the threads window in the debugger, so if you're debugging an app with tons of threads, the name makes it super-easy to find 'the thread you care about' in this window in the debugger.

In short, I just use it because it interacts nicely with the debugger tooling.

like image 43
Brian Avatar answered Oct 22 '22 05:10

Brian