package cn.mldn.demo;
class MyThread implements Runnable{
@Override
public void run() {
for (int i = 0; i < 20; i++) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName() + ",x =" + i);
}
}
}
public class TestDemo{
public static void main(String[] args ) throws Exception{
MyThread mt1 = new MyThread();
Thread t1 = new Thread(mt1 , "a1");
Thread t2 = new Thread(mt1 , "a2");
Thread t3 = new Thread(mt1 , "a3");
**_**t2.setPriority(Thread.MAX_PRIORITY);
t1.setPriority(Thread.MIN_PRIORITY);
t3.setPriority(Thread.NORM_PRIORITY);**_**
t1.start();
t2.start();
t3.start();
}
}
public class TestDemo{
public static void main(String[] args ) throws Exception{
System.out.println(Thread.currentThread().getPriority());
}
}
//优先级为5,最高