NonStop Server for Java 6.0 Programmer's Reference

For the NonStop system, the thread-scheduling algorithm is not preemptive; that is, a thread
continues to run until it explicitly yields or otherwise causes a yield by invoking a blocking operation
on the thread. However, you can assign time-slice to each thread using the
XX:ThreadTimeSlice option.
When a thread gives up control, the runnable threads of the highest priority are run in first-in-first-out
order. A lower priority thread is run (also in first-in-first-out order) only when no runnable threads
of a higher priority are available. Where no runnable user threads are available, an internal NULL
thread is run. This NULL thread wakes up and gives control to other threads on events, such as
signals, timer completions, and I/O completions.
When a Java thread is created, the thread inherits its priority from the thread that created it. The
priority of the thread varies from MIN_PRIORITY (1) to MAX_PRIORITY (10), where the
default priority is NORM_PRIORITY (5). After a thread is created, the setPriority method
can be used to alter the priority of the thread.
The Java virtual machine threads use predetermined priorities, some of which are higher than the
priority of any of the user threads. By default, the -XX:+UseThreadPriorities option is true
and any attempt to alter the option has no effect. Although attempts to use XX: options, which
affect thread priorities, might be accepted at the command line, these options have no effect when
used on the NonStop system.
A selfish thread (a thread that executes in a tight loop without giving up control) could, theoretically,
run forever. However, after a while, the operating system will periodically reduce the priority of
the process in stages, until its priority reaches a very low value.
Timers are never guaranteed to be exact. Invocation of timer callbacks and detection of I/O
completions can be severely impacted by long-running threads.
For a demonstration of scheduling on a NonStop system, review the output of the following program
and its results when run:
RaceDemo.java
public class RaceDemo {
private final static int NUMRUNNERS = 2;
public static void main(String[] args) {
SelfishRunner[] runners=new SelfishRunner[NUMRUNNERS];
for (int i = 0; i < NUMRUNNERS; i++) {
runners[i] = new SelfishRunner(i);
runners[i].setPriority(2);
}
for (int i = 0; i < NUMRUNNERS; i++)
runners[i].start();
}
}
SelfishRunner.java
public class SelfishRunner extends Thread {
private int tick = 1;
private int num;
public SelfishRunner(int num) {
this.num = num;
}
public void run() {
while (tick < 400000) {
tick++;
if ((tick % 50000) == 0)
System.out.println("Thread #"+num+", tick = "+tick);
}
48 Implementation Specifics