1.线程的优先级可以继承
总结:在java 中线程优先级具有继承性,A启动B线程,B线程的优先级是和A线程一样的
(理解:很好理解,若不一样A线程难道还要,执行到B线程的地方不在执行,等待优先级高的线程执行完毕再执行当前线程,这样也不合适啊)
样例:
public class Thread2 extends Thread {
@Override
public void run() {
super.run();
System.out.println("thread2 priority is "+ this.getPriority());
}
public static void main(String[] args) {
Thread.currentThread().setPriority(6);
System.out.println(Thread.currentThread().getPriority());
Thread1 thread1 = new Thread1();
thread1.start();
}
}
public class Thread1 extends Thread{
@Override
public void run() {
super.run();
System.out.println("thread1 priority is" + this.getPriority());
Thread2 thread2 = new Thread2();
thread2.start();
}
}
结果:
6
thread1 priority is 6
thread2 priority is 6
Process finished with exit code 0