Java – specification of Java’s threading model running under Windows XP available anywhere?

documentationjavamultithreading

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.

Threading is not the same on different OS' – "Write Once, Run Anywhere" isn't true for threading.

See http://java.sun.com/docs/hotspot/threads/threads.html

Best Answer

To answer you question most directly, precise semantics on how threads are implemented are deliberately left undefined by the JVM specification.

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.

I have found significant empirical differences between threading under Windows and Linux regarding thread starvation using wait/notify. Linux is significantly more prone to starvation when the many threads contend for a single lock - to the extent that I had to load up 3 orders of magnitude more threads in Windows to cause starvation than in Linux. For heavily contended locks the Java concurrency locks with a fair modifier become critical.

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 thousand) threads to begin to demonstrate starvation problems.

To make matters worse, there have been 3 different threading models under Linux, each of which have different characteristics.

Mostly, threading has been transparent in my experience, but issues of contention deserve careful consideration.

Related Topic