cpu调用线程是随机分配,通过设置priority,提高线程被cpu代用的比例
public class priority8 implements Runnable { @Override public void run() { System.out.println(Thread.currentThread().getName()); } public static void main(String[] args) { Thread thread1 = new Thread(new priority8(),"陈1"); Thread thread2 = new Thread(new priority8(),"陈2"); Thread thread3 = new Thread(new priority8(),"陈3"); thread1.setPriority(Thread.MIN_PRIORITY); thread2.setPriority(Thread.MAX_PRIORITY); thread3.setPriority(Thread.MAX_PRIORITY); thread1.start(); thread2.start(); thread3.start(); } }