public class Test2 {
public static void main(String[] args) {
Thread a = new Thread(new a1());
Thread b = new Thread(new a2());
a.setPriority(Thread.MIN_PRIORITY);
b.setPriority(1);
b.start();
a.start();
}
}
class a1 implements Runnable {
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("低优先级 " + i);
}
}
}
class a2 implements Runnable {
@Override
public void run() {
for (int i = 0; i < 5; i++) {
System.out.println("高优先级 " + i);
}
}
} |