views:

224

answers:

4

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?

+3  A: 

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.

WW
Yes, never rely on finalize or any kind of destructor to clean up critical resources!
Jason Coco
A: 

It's quite often really useful to do thread dumps of production servers to determine causes of hangs/slowdowns. In this case there's usually going to be a large amount of threads in different roles. In a java application you could be looking at quartz threads and possibly different thread pools that an application uses to establish performance guarantees. Arguably the thread pool name is usually more important than the actual thread name, but the individual thread names can also be significant if you're trying to identify a deadlocked thread. Since the threads usually have a name indicating its role, it helps to understand what's going on.

krosenvold
+1  A: 

Sometimes on JEE application servers, it is useful to be able to trace all activity on a single thread, and these are usually given appropriate names by the pooling sub-system, eg. 'http-25', 'http-12' and so on.

grkvlt
+2  A: 

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.

Brian