<p>There are various documents describing threading on Solaris/Linux, but nowwhere describing the Windows implementation. I have a passing interest in this, it seems strange that something so critical is (seemingly) not documented.</p>

<p>Threading is not the same on different OS' - "Write Once, Run Anywhere" isn't true for threading.</p>

<p>See <a href="http://java.sun.com/docs/hotspot/threads/threads.html" rel="nofollow noreferrer">http://java.sun.com/docs/hotspot/threads/threads.html</a></p>

[{'answer_id': 67870, 'author': 'Sebastian Redl', 'author_id': 8922, 'author_profile': 'https://Stackoverflow.com/users/8922', 'pm_score': 0, 'selected': False, 'text': "<p>The document in question discusses the Solaris threading model and how the VM maps to it. This has nothing to do with Linux. Also, the document discusses performance only. The program's overall behaviour should not change no matter what you choose.</p>\n\n<p>Java's exposed threading model is the same on every platform and defined in the Java specifications. To a Java application, the underlying OS should be completely transparent even for threading.</p>\n\n<p>If you have to know, though ... The Sun JVM maps its threads 1:1 to Windows threads. It doesn't use multiple processes or fibers.</p>\n"}, {'answer_id': 67909, 'author': 'William', 'author_id': 9193, 'author_profile': 'https://Stackoverflow.com/users/9193', 'pm_score': -1, 'selected': False, 'text': '<p>That document is a little more about Solaris threading than the Java threading model. All JVMs call the native thread API of the OS they\'re written for so there is always one Java thread for an OS thread. The diagram in the document shows that it\'s not until the threads are in the OS space that they change. Each OS can handle threads in different ways for Windows specific documentation here is a good place to start: <a href="http://msdn.microsoft.com/en-us/library/ms681917(VS.85).aspx" rel="nofollow noreferrer">MSDN About Processes and Threads</a>.</p>\n\n<p>For a long time various flavours of *nix have implemented their threads with processes rather than actual threads it seems that those specific tuning parameters where there to sort of ease the transition to a newer threading model in Solaris. Which made the older model and those JVM options obsolete.</p>\n\n<p>For a list of JVM options for the HotSpot JVM you can look at: <a href="http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp" rel="nofollow noreferrer">HotSpot VM Options</a>. A lot of these are useful for tuning long running applications but you can also get into trouble with them if you don\'t understand what they\'re doing. Also keep in mind that each implementation of the JVM can have a different set of options you won\'t find some of them on IBM\'s VM or BEA\'s. </p>\n'}, {'answer_id': 68903, 'author': 'Chris Broadfoot', 'author_id': 3947, 'author_profile': 'https://Stackoverflow.com/users/3947', 'pm_score': 2, 'selected': False, 'text': "<p>It really depends on the specific JVM implementation. I assume you're wondering about Sun's Windows JVM, and I can tell you with certainty that the Sun JVM maps a Java thread to an OS thread.</p>\n\n<p>You could try spawning up a couple of threads from Java code, open up Task Manager and see what happened.</p>\n"}, {'answer_id': 255653, 'author': 'Lawrence Dol', 'author_id': 8946, 'author_profile': 'https://Stackoverflow.com/users/8946', 'pm_score': 2, 'selected': False, 'text': '<p>To answer you question most directly, precise semantics on how threads are implemented are deliberately left undefined by the JVM specification.</p>\n\n<p>FWIW, Sebastion\'s statement that "Java\'s exposed threading model is the same on every platform and defined in the Java specifications. To a Java application, the underlying OS should be completely transparent even for threading", is inaccurate.</p>\n\n<p>I have found significant empirical differences between threading under Windows and Linux regarding thread starvation using wait/notify.  Linux is <em>significantly</em> more prone to starvation when the many threads contend for a single lock - to the extent that I had to load up 3 <em>orders of magnitude</em> more threads in Windows to cause starvation than in Linux.  For heavily contended locks the Java concurrency locks with a fair modifier become critical.</p>\n\n<p>To illustrate numbers, I had problems under Linux with one lock heavily contended by 31 threads, where the same code under Windows required 10,000 (yes, that\'s 10 <em>thousand</em>) threads to begin to demonstrate starvation problems.</p>\n\n<p>To make matters worse, there have been 3 different threading models under Linux, each of which have different characteristics.</p>\n\n<p>Mostly, threading has been transparent in my experience, but issues of contention deserve careful consideration.</p>\n'}]
['https://Stackoverflow.com/questions/67183', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/8118/']