class Mythread1 implements Runnable {
String name;
public Mythread1(String name) {
this.name=name;
}
public void run() {
for(int i=0;i<20;i++){
try {
System.out.println(name);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class Thread2 {
public static void main(String[] args) {
Thread t1=new Thread(new Mythread1("p1"),"A");
Thread t2=new Thread(new Mythread1("p2"),"B");
Thread t3=new Thread(new Mythread1("p3"),"C");
t1.setPriority(Thread.MIN_PRIORITY); //设置优先级,低
t2.setPriority(Thread.NORM_PRIORITY); //正常
t3.setPriority(Thread.MAX_PRIORITY); //高
t1.start();
t2.start();
t3.start();
}
}
java 多线程之优先级简单代码
最新推荐文章于 2021-08-28 20:13:51 发布