java设置优先级
java线程的调度并不是通过设置优先级就可以搞定的。
public class ThreadDemo {
public static void main(String[] args) {
Runnable myRunnable = new MyThread(); // 创建一个Runnable实现类的对象
Thread thread1 = new Thread(myRunnable, "A");
Thread thread2 = new Thread(myRunnable, "B");
Thread thread3 = new Thread(myRunnable, "C");
thread1.setPriority(Thread.MIN_PRIORITY);
thread2.setPriority(Thread.MIN_PRIORITY);
thread3.setPriority(Thread.MAX_PRIORITY);
thread1.start();
thread2.start();
thread3.start();
}
}
class MyThread implements Runnable {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(Thread.currentThread().getName());
}
}
}
虽然我们对线程的优先级进行了设置,但可以看见,线程的执行并没有按照优先级的顺序来执行

最后
以上就是自信篮球最近收集整理的关于java设置优先级的全部内容,更多相关java设置优先级内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复