【多线程】线程的优先级设置

来源:互联网 发布:客户数据分析 编辑:程序博客网 时间:2024/05/29 18:26

线程的优先级设置

Thread.currentThread().setPriority(Thread.MAX_PRIORITY);//高优先级Thread.currentThread().setPriority(Thread.MIN_PRIORITY);//低优先级

设置优先级时应该通过currentThread()来获取当前的Thread对象,以此Thread对象调用

public final void setPriority(int newPriority)来设置优先级;


其中,参数 newPriority介于10~1之间,因为

java.lang.Threadpublic static final intMAX_PRIORITY10public static final intMIN_PRIORITY1public static final intNORM_PRIORITY5
否则抛出错误

0 0
原创粉丝点击