您好,登錄后才能下訂單哦!
優(yōu)先級(jí)priority,調(diào)用的概率,建議在start之前設(shè)定
.setPriprity(num);可以是數(shù)組或下列常量;
取值1到10,
NORM_PRIORITY 5所有線程默認(rèn)為5
MIN_PRIORITY 1
MAX_PRIORITY 10
.getPriority()獲得當(dāng)前線程優(yōu)先級(jí)
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);
//設(shè)置優(yōu)先級(jí)在啟動(dòng)前
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();
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。