线程优先级
线程优先级的设定并不是你给他设置越高他越先调度而是你给他设置越高他的权重越大,最后调度顺序还是看cpu心情,所以优先级低只是意味着获取调度的概率低,而不是优先级低就比优先级高的后调用,这个都是看cpu调度的只是改变一个权重而已
package Thread; public class TestPriority implements Runnable{ @Override public void run() { System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority()); } public static void main(String[] args) { TestPriority testPriority = new TestPriority(); Thread t1 = new Thread(testPriority,"aa"); t1.setPriority(5); Thread t2 = new Thread(testPriority,"bb"); t2.setPriority(10); Thread t3 = new Thread(testPriority,"cc"); t3.setPriority(1); Thread t4 = new Thread(testPriority,"dd"); t4.setPriority(6); t1.start(); t2.start(); t3.start(); t4.start(); } }
setPriority为这是优先级
getPriority为获取优先级