我正在尝试优先考虑线程 b,但它仍然不起作用,有时在 b 优先级不起作用之前打印线程 t,我不确定代码是否有任何帮助!
public static void main(String[] args) throws Exception {
Thread t = new Thread(new one("this is t thread"));
Thread b = new Thread(new one("this is b thread"));
b.setPriority(10);
t.setPriority(4);
t.start();
b.start();
}
class one implements Runnable {
String name;
public one(String n) {
name = n;
}
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(name);
}
}
}