📄 prioritydemo.java
字号:
import javax.swing.JOptionPane;
class PriorityDemo
{
public static void main(String args[])
{
Priority hpThread,lpThread;
String output;
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
hpThread = new Priority(Thread.MAX_PRIORITY-1);
lpThread = new Priority(Thread.MIN_PRIORITY+2);
// 启动线程
hpThread.start();
lpThread.start();
try {
Thread.sleep(5000);
}
catch (InterruptedException e) {
System.out.println(e.getMessage());
}
// 终止线程
hpThread.stop();
lpThread.stop();
try {
hpThread.thread.join();
lpThread.thread.join();
}
catch (InterruptedException e) {
System.out.println(e.getMessage());
}
output = "High priority thread has run " + hpThread.runtimes + " times\n"
+ "Low priority thread has run " + lpThread.runtimes + " times\n";
JOptionPane.showMessageDialog( null,output );
System.exit( 0 );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -