The range of thread priorities in Java is 1~10, and the default priority is 5. High-priority threads take precedence over low-priority threads.
Example:
package com.ming.thread.threadpriority; public class MyThread extends Thread { public MyThread (String name) { super public void run () { for (int i = 0; i < 5 ; I++ + "(" + Thread. CurrentThread (). GetPriority () + ")" + ", loop" + i); } }}
Packagecom.ming.thread.threadpriority;/*** The priority value of the thread is 1--10 *@authorMing **/ Public classRun { Public Static voidMain (string[] args) {MyThread T1=NewMyThread ("T1"); MyThread T2=NewMyThread ("T2"); MyThread T3=NewMyThread ("T3"); T1.setpriority (6); T2.setpriority (thread.max_priority); T3.setpriority (1); T1.start (); T2.start (); T3.start (); }}
Rather than taking the priority of threads and the order of running results as a measure, a higher priority thread does not have to perform the task in the Run () method every time, that is, the priority of the thread is not related to the order of printing, and the relationship between the two is not associated, and their relationship is nondeterministic and random.
Java multi-threaded priority issues