System.out.println("This is thread-01! " + Thread.currentThread().getPriority());
}
}
};
Thread thread02 = new Thread(){
@Override
public void run(){
for (int i = 0; i < 10; i++) {
System.out.println("This is thread-02! " + Thread.currentThread().getPriority());
}
}
};
thread01.setPriority(1);
thread02.setPriority(10);
// 尽管thread02优先级高于thread01,但是也有可能
thread01.start();
thread02.start();
}
复制代码
线程的让步(yield方法)
立刻让出JVM的调度资源,并且重新参与到竞争中
[code]public static void main(String[] args) { Thread thread01 = new Thread(){ @Override public void run(){ for (int i = 1; i