线程优先级分为三个等级:
MAX_PIORITY:10 优先
MIN_PRIORITY:1
NORM_PRIORITY:5 默认
getPriority:获取优先级
setPriority:设置优先级
线程优先级设置只是设置了概率,并不会设置了优先级就能先执行线程
public class TestPriority { public static void main(String[] args) { A a = new A(); Thread thread = new Thread(a); thread.setPriority(Thread.MAX_PRIORITY); thread.start(); for (int i = 0; i < 50; i++) { System.out.println(thread.currentThread().getName()+i); } } } class A implements Runnable{ @Override public void run() { for (int i = 0; i < 50; i++) { System.out.println(i); } } }