首页 > 学院 > 开发设计 > 正文

多线程2-线程的优先级

2019-11-08 02:55:55
字体:
来源:转载
供稿:网友

线程的优先级

线程的优先级可能影响线程的执行顺序,但也不一定会影响 可以设定抢到CPU资源的速度,不一定每次都抢到

public class ThRun implements Runnable{ public void run(){ try{ Thread.sleep(1000); System.out.PRintln(Thread.currentThread().getName()+":"+i); }catch(InterruptedException e){ e.printStackTrace(); } }}//测试public class ThreadTest{ public void main(String[] args){ Thread t1=new Thread(new ThRun(),"A"); Thread t2=new Thread(new ThRun(),"B"); Thread t3=new Thread(new ThRun(),"C"); t1.setPriority(Thread.MIN_PRIORITY); t2.setPriority(Thread.NORM_PRIORITY); t3.setPriority(Thread.MAX_PRIORITY); t1.start(); t2.start(); t3.start(); }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表