Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Multi-thread programming in Solaris platform



Well, I just read a point of view from the Java book:

For the runtime on a Solaris Operating Environment platform, Java technology does not preempt threads of the same priority.

I don't really believe this point so I install a Solaris 10 X86 version under my VMWare virtual machine.

By running these code, I found some different result:

class Test {
public static void main(String[] args) {
Thread t1 = new Thread(new T1());
Thread t2 = new Thread(new T2());
t1.setPriority(Thread.NORM_PRIORITY);
t2.setPriority(Thread.NORM_PRIORITY);
t1.start();
t2.start();
}
}

class T1 implements Runnable {
public void run() {
for(int i=0; i<10000; i++) { System.out.println("T1: " + i); }
}
}

class T2 implements Runnable {
public void run() {
for(int i=0; i<10000; i++) { System.out.println("------T2: " + i);  }
}
}

Thread T1 interrupted T2 after T2 loop for about 1600 times.

How to explain this viewpoint? Is it just for old Solaris versions? or only for SPARC platforms??

Please help!!

Thanks!!