一、线程调度模型
1. 抢占式调度模型
- 优先级较高的线程抢到CPU时间片的概率就高,优先级相同就随机选择一个线程使其占用CPU
- Java采用的是抢占式调度模型
2. 均分式调度模型
- 平均分配CPU时间片,每个线程占有的CPU时间片长度一样
二、线程调度相关方法
1. setPriority()
2. getPriority()
2.1 线程优先级
public final static int NORM_PRIORITY = 5;
public final static int MIN_PRIORITY = 1;
public final static int MAX_PRIORITY = 10;
2.2 测试用例
public class ThreadTest {
public static void main(String[] args) {
Thread.currentThread().setPriority(1);
Thread currentThread = Thread.currentThread();
Thread thread = new Thread(new MyRunnable())