首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

java中线程优先级是怎么回事给出一个例子

java中线程的优先级用1-10之间的数字表示,数值越大优先级越高,默认的优先级为5。Java中的线程优先级是在Thread类中定义的常量 NORM_PRIORITY : 值为5,MAX_PRIORITY :值为10,MIN_PRIORITY : 值为1,缺省优先级为 NORM_PRIORITY。有关优先级的常用方法有两个:1)final void setPriority(int newp) : 修改线程的当前优先级  2)final int getPriority() : 返回线程的优先级。马克-to-win:线程的优先级不能担保线程的执行次序。优先级高的线程获取CPU执行的几率较大,优先级低的线程也有机会执行。参考http://www.javamex.com/tutorials/threads/priority_what.shtml其中有句:there'd quite possibly be lower-priority threads that barely got any CPU at all, being continually starved by higher-priority threads that needed CPU. So Windows has a fallback mechanism, whereby a thread that hasn't run for a long time is given a temporary priority boost.大致意思:为防止低优先级的线程被饿死,Windows有个抗争的方法, 给低优先级的线程一个优先级的临时提升。。。。。。更多的请大家参考此网站。

01
领券