Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Sun JVM map Java threads to Windows threads?

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?

like image 463
David Kerr Avatar asked Nov 03 '08 15:11

David Kerr


People also ask

How many threads can JVM handle?

Each JVM server can have a maximum of 256 threads to run Java applications. In a CICS region you can have a maximum of 2000 threads. If you have many JVM servers running in the CICS region (for example, more than seven), you cannot set the maximum value for every JVM server.

What are JVM threads?

A Java thread is the execution path in a program. Everything that runs in Java is run in threads. Every application in the JVM world has threads, at least one, even if you don't call it explicitly. It all starts with the main method of your code, which is run in the main application thread.

Are Java threads kernel threads?

Java threads are "user" threads, but under the hood, the Java Virtual Machine is using kernel threads and delegating the user threads CPU time on each kernel thread in its kernel thread pool.


2 Answers

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 manager first).

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

like image 56
TheMarko Avatar answered Oct 24 '22 11:10

TheMarko


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?

like image 33
Miguel Ping Avatar answered Oct 24 '22 11:10

Miguel Ping