Jolt 1.2 Developer's Guide

A RUNNING thread is a currently executing thread.
A RUNNABLE thread can be run once the current thread has relinquished control of the CPU. There can be many threads in the
RUNNABLE state, but only one can be in the RUNNING state. Running a thread means changing the state of a thread from RUNNABLE to
RUNNING, and causing the thread to have control of the Java Virtual Machine (VM).
A BLOCKED thread is a thread that is waiting on the availability of some event or resource.
Note
The Java VM schedules threads of the same priority to run in a round-robin mode.
Preemptive Threading
The main performance difference between the two threading models arises in telling a running thread to relinquish control of the Java VM. In a
preemptive threading environment, the usual procedure is to set a hardware timer that goes off periodically; when the timer goes off, the current
thread is moved from the RUNNING to the RUNNABLE state, and another thread is chosen to run.
Non-Preemptive Threading
In a non-preemptive threading environment, a thread must volunteer to give up control of the CPU and move to the RUNNABLE state. Many of the
methods in the Java language classes contain code that volunteers to give up control, and are typically associated with actions that might take a long
time. For instance, reading from the network will generally cause a thread to wait for a packet to arrive. A thread that is waiting on the availability
of some event or resource is in the BLOCKED state. When the event occurs or the resource becomes available, the thread becomes RUNNABLE.
Using Jolt with Non-Preemptive Threading
If your Jolt-based Java program is running on a non-preemptive threading Virtual Machine (e.g., Sun Solaris), then the program must either:
Occasionally call a method that blocks the thread
Explicitly give up control of the CPU using the Thread.yield() method
The typical usage is to make the following call in all long running code segments or potentially time-consuming loops:
Thread.currentThread.yield();
Without sending this message, the threads used by the Jolt library may never get scheduled, and as such, the Jolt operation will be impaired.
The only virtual machine known to use non-preemptive threading is the Java Developer's Kit (JDK version 1.0, 1.0.1, 1.0.2) machine running on a
Sun platform. If you want your applet to work on JDK 1.0, you must make sure to send the yield messages. As mentioned earlier, some methods
contain yields. An important exception is the System.in.read method. This method does not cause a thread switch. Rather than rely on these
messages, we suggest using yields explicitly.