我打算在我的Java代码中使用线程优先级.应用程序应在我的Linux系统上运行:
>uname -a
Linux <host> 3.0.0-15-generic #26-Ubuntu SMP <date> x86_64 x86_64 x86_64 GNU/Linux
>java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.1)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
Run Code Online (Sandbox Code Playgroud)
在Web上阅读完之后,我现在使用以下命令启动我的测试应用程序:
sudo java -XX:+UseThreadPriorities -XX:ThreadPriorityPolicy=1 -jar ThreadPriorityTest.jar
Run Code Online (Sandbox Code Playgroud)
测试应用程序包含以下两个类:
package ch.mypackage;
public class CountingRunnable implements Runnable{
private long count=0;
private boolean goOn=true;
public long getCount() {
return count;
}
public void stop(){
goOn=false;
}
public void run() {
for(long iteration=0;goOn&&iteration<Long.MAX_VALUE;++iteration){
++count;
}
}
}
package ch.mypackage;
public class PriorizedCountingThreads …Run Code Online (Sandbox Code Playgroud)