4.5.2 Using Jolt with Non-Preemptive Threading
If your Jolt-based Java program is running on a non-preemptive threading Virtual Machine (such as Sun Solaris), the program must either:
- Occasionally call a method that blocks the thread, or
- 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 is impaired.
The only virtual machine known to use non-preemptive threading is the Java Developer’s Kit
(JDK) machine running on a Sun platform. If you want your applet to work on JDK 1.3, 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.
Parent topic: Multithreaded Applications