当前位置:网站首页>线程优先级

线程优先级

2022-06-26 05:05:00 浅墨cgz

/** *观察线程状态 */
public class Allstate{
    
   public static viod main(String[] args){
    
   Thread t = new Thread(()->{
    
   		System.out.println("……");
   		})
   //观察状态
   State state = t.getState();
   System.out.println(state);//NEW
	}
}

线程的状态,五个状态:可以通过state查看。

线程的优先级:
范围从1到10
Thread.MIN_PRIORITY = 1
Thread.MAX_PRIORITY = 10
Thread.NORM_PRIORITY = 5
使用setPriority(int newPriority);
getPriority();
获得,和设定优先级;
设定建议在start()调用前。
注意:优先级第知识意味着获得调度的概率低。并不是绝对先调用优先级高先调。

原网站

版权声明
本文为[浅墨cgz]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_33592002/article/details/91351693