JAVA CORE - Trang 167

!

%

(

$

+

%

%

)

%

Priority t1,t2,t3;

public PriorityDemo(){

t1 = new Priority();

t1.start();

t2 = new Priority();

t2.start();

t3 = new Priority();

t3.start();

}

public static void main(String args[]){

new PriorityDemo();

}

class Priority extends Thread implements Runnable{

int sleep;

int prio = 3;

public Priority(){

sleep += 100;

prio++;

setPriority(prio);

}

public void run(){

try{

Thread.sleep(sleep);

System.out.println("Name "+ getName()+" Priority = "+

getPriority());

}catch(InterruptedException e){

System.out.println(e.getMessage());

}

}

}


}


Kết quả hiển thị như hình 8.4

Hình 8.4 Quyền ưu tiên luồng

Liên Kết Chia Sẽ

** Đây là liên kết chia sẻ bới cộng đồng người dùng, chúng tôi không chịu trách nhiệm gì về nội dung của các thông tin này. Nếu có liên kết nào không phù hợp xin hãy báo cho admin.