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?

Asked by: Adelaide971 | Posted: 23-01-2022

Answer 1

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.

Answered by: Arnold645 | Posted: 24-02-2022

Answer 2

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?

Answered by: Madaline950 | Posted: 24-02-2022

Answer 3

How to name a Win32 thread

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

Answered by: Leonardo864 | Posted: 24-02-2022

Answer 4

JVM specification doesn't say anything strictly in this regard. Its left upto the JVM implementors to map Java theads to platform theads( Windows, Linux etc). Also its hard to believe that there will be one to one mapping between Java threads and OS threads.

Answered by: Catherine304 | Posted: 24-02-2022

Similar questions

java - How do I get my Threads to not block one another?

I have 2 Threads, one that's polling a mailbox for messages then sleeping while (!quit) and another that's supposed to change the quit flag should the user enter 'Q'. It seems that the scanning Thread blocks the other Thread from executing until there's some input (usually 2 lines). I've tried changing the priority of the Threads and the order in which they start, to no avail.

java - How can I make sure N threads run at roughly the same speed?

I'm toying with the idea of writing a physics simulation software in which each physical element would be simulated in its own thread. There would be several advantages to this approach. It would be conceptually very close to how the real world works. It would be much easier to scale the system to multiple machines. However, for this to work I need to make sure that all threads run at the same speed, with a...

java - Threads in Spring

I have a Web application using spring and hibernate and struts (it runs on Tomcat) The call sequence is something like this... Struts action calls spring service bean which in turn calls Spring DAO bean. The DAO implementation is a Hibernate implementation. The question is Would all my spring beans be running in the same thread ? Can I store something in the ThreadLocal and get it i...

Threads in Java and Python

i have few questions about threads in Python and Java... Is it possible to give priorities to Python threads, as it is in Java? How can I kill, stop, suspend and interrupt thread in Python? Thread groups - what are they really for? Does Python support them too? Synchronization - in Java we use simply keyword synchorinized for a method, object...What about Python? Tnx...

serial port - threads for reading and writing java

i'm reading data from serial port for average interval say 1 second,and at the same time writing read data to textArea and textfile,problem is i'm not getting correct data at some time,may be because i'm doing all three process in a single program,how to do writing to text area and text file by separate thred? this is my code: import; import; import

java - How do I create daemon threads?

Can a java programmer can create daemon threads manually? How is it?

jvm - Name 2 java VM threads

I am studying for a java exam and on a past exam the lecturer asked this question and im wondering if someone can help me understand it: In the context of java explain threads. Give an example of when you might use a thread. Name two java virtual machine threads. The first two parts of the question are easy enough but the part about naming the two VM threads is really stumping m...

daemon threads in java

i ran jconsole, i see some live threads count and daemon threads count .... i run no other java app/classes .... i could see the list of live threads but not daemon thread .... is there a way to know what is the list of deamon threads ?

dll - Java: Load the same dynamic library in two threads (both threads in the same JVM)

I am using a library (written in C) that is not reentrant(i.e no function in the library is reentrant). Suppose I have loaded the library via System.load to get the handle say 'v'. I cannot use v in two threads because of the reentrancy issues (tried but nonsense results). I could use locks, but that defeats any parallelism i could have gained. What I'd like to do is start two threads, and in each thread load the l...

Java Threads and MySQL

I have a threaded chat server application which requires MySQL authencation. Is the best way to have 1 class create the MySQL connection, keep that connection open and let every thread use that connection but use own Query handler? Or is it better to have all threads make a seperate connection to MySQL to authencate? Or is it better to let 1 class handle the queries AND connections? We are ...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)