setPriority优先级
package com.com.Prioity;
public class MyThread extends Thread{
public MyThread(String name){
super.setName(name);
}
@Override
public void run() {
for (int i = 0; i < 1000; i++) {
System.out.println(super.getName()+"==" + i);
}
}
}
package com.com.Prioity;
public class test {
public static void main(String[] args) {
MyThread mt1 = new MyThread("线程1");
MyThread mt2 = new MyThread("线程2");
mt2.setPriority(10);//有优先级 并不意味着独占cpu
//优先级低 不代表不执行
mt1.setPriority(1);
mt1.start();
mt2.start();
}
}

浙公网安备 33010602011771号