views:

1420

answers:

3

My application uses loads of Java threads. I am looking for a reliable understanding how the JVM (version 5 and 6) maps the Java threads to underlying Windows threads. I know there is a document for mapping to Solaris threads, but not Windows.

Why doesn't Sun publish this information?

I want to know if there's a 1:1 mapping, or if it varies by JVM, by -server option, by workload, etc, etc.

I know I am not "supposed" to care, I should write properly synchronisd code, but I am inheriting a large body of code...

Also, does anyone know how to give names to Windows threads?

+3  A: 

Don't have a document for you, but from the Threads column in the task-manager you can pretty reliably guess that it maps 1:1 to native threads (you need to enable the Threads column in the task manger first).

Oh, almost forgot, you can download the jdk src here and look yourself.

TheMarko
+1  A: 

The mapping is platform-dependent, however I found an interesting comparison between platform threads for the vm (although probably a bit old). The bottom line is: you don't need to know. What you probably are more interested is to know about green threads (if you don't know already).

As for the naming question: Doesn't the constructor allow you to name a thread? Or do you mean name them and view their name on some windows thread browser?

Miguel Ping
A: 

How to name a Win32 thread

Unfortunately, this seems like it's impossible or at least very hard to do inside the Windows JVM.

MSalters
You could always wrap some JNI around that code if you wanted to use it.
James Van Huis
You might have a hard time finding the windows thread ID - wouldn't match the threadID returned by the JVM. But, seems to me like this is something you really shouldn't need to do in Java in the first place.
matt b
I've recently been dealing with JNI code that creates Win32 AccessTokens, and it may be that these tokens only work in the OS thread where they were created.. not sure though..
David Leonard