日期:2014-05-18  浏览次数:20636 次

关于java多线程优先级
这个程序是从书上抄的,按照这个优先级的设置,应该是高优先级的运行次数远远超过低优先级的线程,但是我跑出来的结果为什么两个值差不多?
// Demonstrate thread priorities.
class clicker implements Runnable {
int click = 0;
Thread t;
private volatile boolean running = true;
public clicker(int p) {
t = new Thread(this);
t.setPriority(p);
}
public void run() {
while (running) {
click++;
}
}
public void stop() {
running = false;
}
public void start() {
t.start();
}
}
class HiLoPri {
public static void main(String args[]) {
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
clicker hi = new clicker(Thread.NORM_PRIORITY + 2);
clicker lo = new clicker(Thread.NORM_PRIORITY - 2);
lo.start();
hi.start();
try {
------解决方案--------------------
引用:
Quote: 引用:

这就好像,我说了,你听不听就不知道了


啥意思 求大神指导
http://bbs.csdn.net/topics/390502387