线程的调度
线程的优先级等级
MAX_PRIORITY:10
MIN_PRIORITY:1
NORM_PRIORITY:5
线程优先级涉及的方法
getPriortiy():返回线程的优先级
setPriority(int newPriortiy):改变线程的优先级
线程创建时继承父线程的优先级
第优先级只是获得调度的概率低,并非一定是在高优先级线程之后才被调用。
package threadStudy;
public class Main {
public static void main(String[] args) {
MyThread mythread = new MyThread("MyThread");
mythread.setPriority(Thread.MAX_PRIORITY);
mythread.start();
Thread.currentThread().setName("MainThread");
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
for(int i = 0; i <= 100; i++){
System.out.println(Thread.currentThread().getName()+"-"+i);
}
}
}
package threadStudy;
public class MyThread extends Thread{
private String threadName;
public MyThread(String threadName){
super(threadName);
}
public void run(){
for(int i = 0; i <= 100; i++){
System.out.println(this.currentThread().getName()+"***"+i);
}
}
}