java 如何设置线程的优先级
发布网友
发布时间:2022-04-23 06:11
我来回答
共1个回答
热心网友
时间:2023-10-18 13:35
public class MyThread1 extends Thread{
MyThread1(String name){
super(name);
}
@Override
public void run() {
for(int i = 0; i < 10000 ; i++){
System.out.println(getName()+": "+i);
}
}
}
public class MyThread2 extends Thread{
MyThread2(String name){
super(name);
}
@Override
public void run() {
for(int i = 0; i < 10000 ; i++){
System.out.println(getName()+": "+i);
}
}
}
public class Test {
public static void main(String[] args) {
MyThread1 t1 = new MyThread1("t1");
MyThread1 t2 = new MyThread1("t2");
t1.setPriority(Thread.NORM_PRIORITY + 3);
t1.start();
t2.start();
}
}