package Thread.Thread02;
/**
* FileName: ThreadPriorityDemo
* Author: lps
* Date: 2022/3/29 15:08
* Sign:刘品水 Q:1944900433
*
*
* void setPriority(int newPriority)
* 更改此线程的优先级。
*/
public class ThreadPriorityDemo {
public static void main(String[] args) {
ThreadPriority tp1 = new ThreadPriority();
ThreadPriority tp2 = new ThreadPriority();
ThreadPriority tp3 = new ThreadPriority();
tp1.setName("高铁");
tp2.setName("飞机");
tp3.setName("狗爬");
// System.out.println(tp1.getPriority());//5
//
// System.out.println(tp2.getPriority());//5
//
// System.out.println(tp3.getPriority());//5
//tp1.setPriority(9);
//IllegalArgumentException
//IllegalArgumentException -如果优先级不在范围 MIN_PRIORITY到 MAX_PRIORITY。
//SecurityException -如果当前线程不能修改这个线程。
// System.out.println(Thread.MAX_PRIORITY);//10
//
// System.out.println(Thread.MIN_PRIORITY);//1
//
// System.out.println(Thread.NORM_PRIORITY);//5
//设置正确的优先级
tp1.setPriority(5);
tp2.setPriority(10);
tp3.setPriority(1);
tp1.start();
tp2.start();
tp3.start();
// tp3.run();
// tp1.run();
// tp2.run();
}
}
package Thread.Thread02;
/**
* FileName: ThreadPriority
* Author: lps
* Date: 2022/3/29 15:09
* Sign:刘品水 Q:1944900433
*/
public class ThreadPriority extends Thread{
@Override
public void run() {
for (int i = 0; i < 100; i++) {
System.out.println(getName()+":"+i);
}
}
}