Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 5 of 6

This threading model gives you an enormous amount of flexibility. You can choose between an extremely fast (but strictly concurrent) cooperative system, a slower (but parallel) preemptive system, or any combination of the two.
So why does this matter to a Java programmer? The main issue is that the choice of threading model is entirely up to the VM -- you have no control. For example, early versions of the Solaris VM were strictly cooperative. Java threads were all green threads sharing a single LWP. The current version of the Solaris VM, however, uses several LWPs. Similarly, the NT VMs don't have the equivalent of green threads, so they're always preemptive. In order to write platform-independent code, you must make two seemingly contradictory assumptions:
synchronized keyword carefully to assure that non-atomic operations work correctly.yield() and sleep() in appropriate places (or make blocking I/O calls). For example, you might want to consider calling yield() every one hundred iterations or so of a long loop, or voluntarily going to sleep for a few milliseconds every so often to
give lower-priority threads a chance to run. (yield() will yield control only to threads running at your priority level or higher).
So, those are the main OS-level issues you must consider when you're writing a Java program. Since you can make no assumptions
about your operating environment, you have to program for the worst case. For example, you have to assume you can be preempted
at any time, so you must use synchronized appropriately, but you must also assume that you will never be preempted, so you must also use yield(), sleep(), or occasionally blocking I/O calls to permit other threads to run. You can't assume priority levels 1 and 2 are different.
They might not be after NT has mapped Java's 10 levels into its 7 levels. You can't assume that a priority level 2 thread
will always be higher priority than one that runs at level 1.
Subsequent articles will get into considerable detail about various thread-related programming problems and solutions. Here's the roadmap for the rest of the series: