Hello,

I would like to know the "exact" thread scheduling policy in JDK on linux
based on a native thread model.
I am currently using

java version "1.2.2"
Classic VM (build Linux_JDK_1.2.2_RC4, native threads, sunwjit)

I examined the following simple test program with both a green thread
and a native thread model. In a green thread model, the strict priority-based
scheduling is exforced, so the priority specified by Thread.setPriority
method are considered by the scheduler in Java VM.

On the other hand, in a native thread model, I am not sure whether the
thread with maximum priority get the preference or not.
Both threads get pretty fair amout of time slices in turn. Furthermore,
the Thread.yield() in Thread 1 does not cause to switch to the other thread to execute,
and Thread 1 continues to run for a while.

import java.lang.*;

class TestThread extends Thread {
String id;

public TestThread(String s) {
id = s;
}

public void run() {
int i;
for (i = 0; i < 1000; i++) {
if(i == 500 && id.equals("Thread 1")){
System.out.println("Thread 1 yielding..\n");
yield();
}
System.out.println(id+":"+(new Integer(i)).toString());
}
}

public static void main(String args[]){
TestThread t1, t2;
t1 = new TestThread("Thread 1");
t1.setPriority(Thread.MIN_PRIORITY);
t1.start();
t2 = new TestThread("Thread 2");
t2.setPriority(Thread.MAX_PRIORITY);
t2.start();
}

I know that the spec of JVM does not say much about scheduling
policy.

"Every thread has a priority. When there is competition for processing
resources, threads with higher priority are generally executed in
preference to threads with lower priority. Such preference is not,
however, a guarantee that the highest priority thread will always be
running [...]"

It woudl be very nice to have the pricise description of
scheduling policy for JVM on Linux in a native thread model.
I particularly would like to know the following points.

- Is it meaning full to specify thread priority?
- Does Thread.yield work in a native thread model?

Kazuhiro





---------------------------------------------------------------------- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to