getpriority java_Java Thread getPriority()方法

Thread类的getPriority()方法用于检查线程的优先级。 当创建一个线程时,它会为它分配一些优先级。线程的优先级可以由JVM或程序员在创建线程时明确指定。

线程的优先级在1到10的范围内。线程的默认优先级为5。

语法

public final int getPriority()

返回值

它返回线程的优先级的整数值。

示例代码

public class JavaGetPriorityExp extends Thread { public void run() { System.out.println("running thread name is:"+Thread.currentThread().getName()); } public static void main(String args[]) { // creating two threads JavaGetPriorityExp t1 = new JavaGetPriorityExp(); JavaGetPriorityExp t2 = new JavaGetPriorityExp(); // print the default priority value of thread System.out.println("t1 thread priority : " + t1.getPriority()); System.out.println("t2 thread priority : " + t2.getPriority()); // this will call the run() method t1.start(); t2.start(); } }

执行上面示例代码,得到以下结果:

t1 thread priority : 5 t2 thread priority : 5 running thread name is:Thread-0 running thread name is:Thread-1

¥ 我要打赏 纠错/补充 收藏

哥,这回真没有了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值