优先级问题
来源:互联网 发布:淘宝买汽车配件 编辑:程序博客网 时间:2024/06/06 01:30
优先级实例
public class Priority {
public final static int MIN_PRIORITY = 1;
public final static int NORM_PRIORITY = 5;
public final static int MAX_PRIORITY = 10;
public static class HightPriority extends Thread {
static int count = 0;
@Override
public void run() {
while (true) {
synchronized (Priority.class) {
count++;
if (count > 100000) {
System.out.println("HightPriority is complete!");
break;
}
}
}
}
}
public static class LowPriority extends Thread {
static int count = 0;
@Override
public void run() {
while (true) {
synchronized (Priority.class) {
count++;
if (count > 100000) {
System.out.println("LowPriority is complete!");
break;
}
}
}
}
}
public static void main(String[] args) throws InterruptedException {
Thread high = new HightPriority();
Thread low = new LowPriority();
high.setPriority(Thread.MAX_PRIORITY);
low.setPriority(Thread.MIN_PRIORITY);
low.start();
high.start();
}
}
大部分情况下,高优先级都会首先完成,不过有时候也会出现低优先级的先完成。
每天努力一点,每天都在进步!
阅读全文
0 0
- 优先级问题。
- 优先级问题
- 优先级问题
- 优先级问题
- 优先级问题
- 优先级问题
- 优先级问题
- 优先级问题
- 优先级翻转问题
- CSS优先级问题
- [C]*与++优先级问题
- 运算符优先级问题
- 优先级反转问题
- CSS优先级问题
- *string++优先级的问题
- 线程优先级问题
- prototype优先级的问题
- CSS选择器优先级问题
- Zookeeper learner(follower和obverser)的配置
- 位运算符总结
- java_jdbc基础笔记
- FLASH、EPPROM、RAM等存储器
- 【偶数求和】
- 优先级问题
- 实地址模式与保护模式
- 智能一代云平台(三十四):后端架构一些总结
- JAVA 攻城狮 第六天
- ItemTouchHelper实现部分响应拖动
- 数据压缩原理与应用 实验六 MPEG音频编码实验
- hibernate中的@OneToMany、@ManyToOne以及@ManyToMany
- java异常机制分析
- Nginx搭建