/*设置线程的优先级与线程礼让*/
class MyThread9 implements Runnable{
public void run(){
for(int i=5; i>0; i--){
if(i==3){
System.out.println("线程礼让:");
Thread.currentThread().yield(); //线程礼让
}
System.out.println(Thread.currentThread().getName()+"运行"+i);
}
}
}
public class ThreadSetPriority {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread8 mt8 = new MyThread8();
Thread th = new Thread(mt8,"线程A");
Thread th1 = new Thread(mt8,"线程B");
Thread th2 = new Thread(mt8,"线程C");
th.setPriority(Thread.MAX_PRIORITY); //设置线程的优先级
th1.setPriority(Thread.MIN_PRIORITY);
th2.setPriority(Thread.NORM_PRIORITY);
th.start();
th1.start();
th2.start();
}
}
class MyThread9 implements Runnable{
public void run(){
for(int i=5; i>0; i--){
if(i==3){
System.out.println("线程礼让:");
Thread.currentThread().yield(); //线程礼让
}
System.out.println(Thread.currentThread().getName()+"运行"+i);
}
}
}
public class ThreadSetPriority {
public static void main(String[] args) {
// TODO Auto-generated method stub
MyThread8 mt8 = new MyThread8();
Thread th = new Thread(mt8,"线程A");
Thread th1 = new Thread(mt8,"线程B");
Thread th2 = new Thread(mt8,"线程C");
th.setPriority(Thread.MAX_PRIORITY); //设置线程的优先级
th1.setPriority(Thread.MIN_PRIORITY);
th2.setPriority(Thread.NORM_PRIORITY);
th.start();
th1.start();
th2.start();
}
}