java线程池多线程优先级_Java线程优先级

Java线程的优先级用于描述线程被调度执行的顺序,范围在1到10之间。MIN_PRIORITY是1,NORM_PRIORITY默认为5,MAX_PRIORITY是10。可以通过getPriority()获取和setPriority(int newPriority)设置线程优先级。然而,高优先级线程并不总是先于低优先级线程执行,这依赖于线程调度器。
摘要由CSDN通过智能技术生成

java线程池多线程优先级

Priority of a thread describes how early it gets execution and selected by the thread scheduler. In Java, when we create a thread, always a priority is assigned to it. In a Multithreading environment, the processor assigns a priority to a thread scheduler. The priority is given by the JVM or by the programmer itself explicitly. The range of the priority is between 1 to 10 and there are three constant variables which are static and used to fetch priority of a Thread. They are as following:

线程的优先级描述了线程调度程序提早执行和选择线程的时间。 在Java中,当我们创建线程时,总是为其分配优先级。 在多线程环境中,处理器将优先级分配给线程调度程序。 优先级由JVM或程序员本身明确指定。 优先级的范围在1到10之间,并且有三个常量,它们是静态的,用于获取线程的优先级。 它们如下:

1. public static int MIN_PRIORITY (1. public static int MIN_PRIORITY)

It holds the minimum priority that can be given to a thread. The value for this is 1.

它拥有可以赋予线程的最低优先级。 该值为1。

2. public static int NORM_PRIORITY (2. public static int NORM_PRIORITY)

It is the default priority that is given to a thread if it is not defined. The value for this is 0.

如果未定义,则它是赋予线程的默认优先级。 该值为0。

3. public static int MAX_PRIORITY (3. public static int MAX_PRIORITY)

It is the maximum priority that can be given to a thread. The valu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值