NonStop Server for Java Programmer's Reference (NSJ 4.2+)
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);
}
}
}
On the NonStop system, the execution of threads is not time-sliced. Messages from one thread precede those from
the other thread as shown below for thread 0 and thread 1.
Thread #0, tick = 50000
Thread #0, tick = 100000
Thread #0, tick = 150000
Thread #0, tick = 200000
Thread #0, tick = 250000
Thread #0, tick = 300000
Thread #0, tick = 350000
Thread #0, tick = 400000
Thread #1, tick = 500000
Thread #1, tick = 100000
Thread #1, tick = 150000
Threading Considerations for Java Code
A thread-aware function blocks only the thread calling that function, rather than blocking all threads in the process.
At the Java program level, the following blocking operations are thread-aware and, therefore, block only the thread
performing the operation rather than blocking all threads in Java: