线程优先级
阿里云服务器,每月低至7.8元,项目演示即建站必备,比腾讯云更便宜,并且不需学生认证,从此链接购买有效:去购买
每个线程都有一个优先级。 优先级由1到10之间的数字表示。在大多数情况下,线程计划根据线程的优先级调度(称为抢占调度)。 但它不能保证,因为它依赖于JVM规范,它选择哪个调度。 Thread类中定义的3个常量:
线程的默认优先级为5(NORM_PRIORITY)。 MIN_PRIORITY的值为1,MAX_PRIORITY的值为10。 线程优先级示例:相关实例: class TestMultiPriority1 extends Thread{ public void run(){ System.out.println("running thread name is:"+Thread.currentThread().getName()); System.out.println("running thread priority is:"+Thread.currentThread().getPriority()); } public static void main(String args[]){ TestMultiPriority1 m1=new TestMultiPriority1(); TestMultiPriority1 m2=new TestMultiPriority1(); m1.setPriority(Thread.MIN_PRIORITY); m2.setPriority(Thread.MAX_PRIORITY); m1.start(); m2.start(); } } Output:running thread name is:Thread-0 running thread priority is:10 running thread name is:Thread-1 running thread priority is:1阿里云服务器,每月低至7.8元,项目演示即建站必备,比腾讯云更便宜,并且不需学生认证,从此链接购买有效: 去购买
版权声明:本站所有教程均为本站原创或翻译,转载请注明出处,请尊重他人劳动果实。请记住本站地址:www.yuanjiaocheng.net (猿教程) 作者:卿文刚
本文标题: C#环境 本文地址:http://www.yuanjiaocheng.net/Java/priority-of-a-thread-java.html |