1.10.3优先级具有随机性

继续更改上面1.10.2的优先级使他们俩的优先级差不多

 1 package com.cky.prioritydemo;
 2 
 3 /**
 4  * Created by edison on 2017/12/3.
 5  */
 6 public class PriorityTest {
 7     public static void main(String[] args) {
 8         for (int i = 0; i < 5; i++) {
 9             MyThread1 th1 = new MyThread1();
10             th1.setPriority(5);
11             th1.start();
12             MyThread2 th2 = new MyThread2();
13             th2.setPriority(6);
14             th2.start();
15         }
16     }
17 }
C:itsoftjdkinjava -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:itsoftideaIntelliJ IDEA 2016.3.3in" -Dfile.encoding=UTF-8 -classpath "C:itsoftjdkjrelibcharsets.jar;C:itsoftjdkjrelibdeploy.jar;C:itsoftjdkjrelibextaccess-bridge-32.jar;C:itsoftjdkjrelibextcldrdata.jar;C:itsoftjdkjrelibextdnsns.jar;C:itsoftjdkjrelibextjaccess.jar;C:itsoftjdkjrelibextjfxrt.jar;C:itsoftjdkjrelibextlocaledata.jar;C:itsoftjdkjrelibext
ashorn.jar;C:itsoftjdkjrelibextsunec.jar;C:itsoftjdkjrelibextsunjce_provider.jar;C:itsoftjdkjrelibextsunmscapi.jar;C:itsoftjdkjrelibextsunpkcs11.jar;C:itsoftjdkjrelibextzipfs.jar;C:itsoftjdkjrelibjavaws.jar;C:itsoftjdkjrelibjce.jar;C:itsoftjdkjrelibjfr.jar;C:itsoftjdkjrelibjfxswt.jar;C:itsoftjdkjrelibjsse.jar;C:itsoftjdkjrelibmanagement-agent.jar;C:itsoftjdkjrelibplugin.jar;C:itsoftjdkjrelib
esources.jar;C:itsoftjdkjrelib
t.jar;C:多线程核心技术第一章outproduction第一章;C:itsoftideaIntelliJ IDEA 2016.3.3libidea_rt.jar" com.intellij.rt.execution.application.AppMain com.cky.prioritydemo.PriorityTest
thread 1 use time=516
thread 1 use time=531
thread 2 use time=547
thread 2 use time=578
thread 1 use time=578
thread 1 use time=578
thread 2 use time=594
thread 1 use time=594
thread 2 use time=594
thread 2 use time=594

Process finished with exit code 0

结果说明线程的优先级与打印顺序无关,不要将两者的关系关联,他们的关系有不确定性和随机性

原文地址:https://www.cnblogs.com/edison20161121/p/7954803.html