📄 threadprioritydemo.java
字号:
public class ThreadPriorityDemo extends Thread
{
public ThreadPriorityDemo(String msg){
super(msg);
System.out.println("Thread " + msg + " is created");
}
public void run(){
System.out.println(getName() + "\tstart running");
for(int i=1; i<3; i++)
System.out.println(toString());
System.out.println(getName() + " end!");
}
public String toString(){
return(getName() + " priority :" + getPriority());//输出当前线程名及其优先级
}
public static void main(String []args){
ThreadPriorityDemo t1 = new ThreadPriorityDemo("Thread1");//创建线程
ThreadPriorityDemo t2 = new ThreadPriorityDemo("Thread2");
ThreadPriorityDemo t3 = new ThreadPriorityDemo("Thread3");
ThreadPriorityDemo t4 = new ThreadPriorityDemo("Thread4");
t1.start(); //启动线程
t2.start();
t3.start();
t4.start();
System.out.print("reset the priority.......\n");
t1.setPriority(MIN_PRIORITY); //重新设定线程的优先级
t2.setPriority(MAX_PRIORITY); //线程的默认优先级是5
t4.setPriority(8);
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -