Package Com.itbuluoge.mythread;class Simplethread extends thread{private int priority;public simplethread (int i) { Priority=i;} public void Run () {Thread.CurrentThread (). SetPriority (priority), for (int i=0;i<10000;i++) {try {thread.sleep (100);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} SYSTEM.OUT.PRINTLN (priority);}}} public class Prioritydemo {/** * @param args */public static void main (string[] args) {//TODO auto-generated method stubs Implethread high=new Simplethread (thread.max_priority); Simplethread low=new Simplethread (thread.min_priority); High.start (); Low.start ();}}
As seen in the code above, the two threads executed, each setting the highest and lowest priority, we can look at the output:
10
1
10
1
10
1
10
1
10
1
10
1
10
1
10
1
1
10
1
10
10
1
10
1
1
Can be preliminarily discovered. High priority, the resulting scheduling will be more preferential. But it's not obvious.
Java Multi-threaded setting priority