我正在尝试编写一个小型测试,其中我正尝试更改Java线程的优先级,以将其设置为科学Linux框上的实时属性。在Java中使用JNI调用更改线程优先级
我认为这需要使用JNI调用完成,因为使用Thread.MAX_PRIORITY或Thread.MIN_PRIORITY将永远不会将其映射到实时优先级。
我很难过,我怎样才能从我的本地代码访问我的Java线程。以下是我的java程序:
public class ThreadPriorityTest implements Runnable {
public static int numThreads;
public void run() {
System.out.println("***Java: Changing thread priorities");
changePriority();
}
public static synchronized native void changePriority();
public static void main(String[] args) {
if(args.length != 1) {
System.out.println("Usage: ThreadPriorityTest <num_of_threads>");
System.exit(0);
}
numThreads = Integer.parseInt(args[0]);
for(int i = 0; i < numThreads; i++) {
Thread t = new Thread(new ThreadPriorityTest());
t.start();
}
}
}