📄 newthreaddemo.java
字号:
package java_Thread;
public class NewThreadDemo{
public static void main(String args[]){
NewThread t1 = new NewThread("Thread 1");
NewThread t2 = new NewThread("Thread 2");
t1.setPriority(Thread.NORM_PRIORITY-3);//设置优先级为2;
t2.setPriority(Thread.NORM_PRIORITY+3);//设置优先级为8
t1.start();
t2.start();
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
System.out.println(ex.getMessage());
}
System.out.println("Thread 1 Priority is : " + t1.getPriority() +
" Result of Count is : " + t1.result());
System.out.println("Thread 2 Priority is : " + t2.getPriority() +
" Result of Count is : " + t2.result());
t1.setPriority(Thread.MAX_PRIORITY);// 重新设置t1的优先级为最大。
try {
Thread.sleep(500);
} catch (InterruptedException ex1) {
System.out.println(ex1.getMessage());
}
t1.stopThread();
t2.stopThread();
System.out.println("Thread 1 Priority is : " + t1.getPriority() +
" Result of Count is : " + t1.result());
System.out.println("Thread 2 Priority is : " + t2.getPriority() +
" Result of Count is : " + t2.result());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -