您好,登錄后才能下訂單哦!
優先級priority,調用的概率,建議在start之前設定
.setPriprity(num);可以是數組或下列常量;
取值1到10,
NORM_PRIORITY 5所有線程默認為5
MIN_PRIORITY 1
MAX_PRIORITY 10
.getPriority()獲得當前線程優先級
public class n {
public static void main(String[]args) throws InterruptedException
{
System.out.println(Thread.currentThread().getPriority());
test t=new test();
Thread t1=new Thread(t);
Thread t2=new Thread(t);
Thread t3=new Thread(t);
Thread t4=new Thread(t);
Thread t5=new Thread(t);
Thread t6=new Thread(t);
t1.setPriority(Thread.MAX_PRIORITY);
t2.setPriority(Thread.MAX_PRIORITY);
t3.setPriority(Thread.MAX_PRIORITY);
t4.setPriority(Thread.MIN_PRIORITY);
t5.setPriority(Thread.MIN_PRIORITY);
t6.setPriority(Thread.MIN_PRIORITY);
//設置優先級在啟動前
t1.start();
t2.start();
t3.start();
t4.start();
t5.start();
t6.start();
}
}
class test implements Runnable
{
public void run()
{
System.out.println(Thread.currentThread().getName()+"-->"+Thread.currentThread().getPriority());
Thread.yield();
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。