博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAVA线程调度的优先级
阅读量:7236 次
发布时间:2019-06-29

本文共 925 字,大约阅读时间需要 3 分钟。

线程的优先级用数字来表示,默认范围是1到10,即Thread.MIN_PRIORITY到Thread.MAX_PRIORTY.一个线程的默认优先级是5,即Thread.NORM_PRIORTY

对优先级操作的方法:

int getPriority():得到线程的优先级

void setPriority(int newPriority):当线程被创建后,可通过此方法改变线程的优先级

必须指出的是:线程的优先级无法保障线程的执行次序。只不过,优先级高的线程获取CPU资源的概率较大。

class MyThread extends Thread{    String message;    MyThread(String message){        this.message=message;    }    public void run(){        for(int i=0;i<3;i++){            System.out.println(message+" "+getPriority());        }    }} public class PriorityThread{    public static void main(String args[]){        Thread t1=new MyThread("T1");        t1.setPriority(Thread.MIN_PRIORITY);        t1.start();                Thread t2=new MyThread("T2");        t2.setPriority(Thread.MAX_PRIORITY);        t2.start();                Thread t3=new MyThread("T3");        t3.setPriority(Thread.MAX_PRIORITY);        t3.start();    }}

 

转载于:https://www.cnblogs.com/scf141592/p/5768172.html

你可能感兴趣的文章
使用Xamarin.Forms平台开发移动应用指南
查看>>
javascript中的链表结构
查看>>
微信开发-ACCESS TOKEN 过期失效解决方案
查看>>
某硕笔试题mysql数据库部分(较为全面)
查看>>
jQuery刷新包含的<jsp:include>页面
查看>>
领导者/追随者(Leader/Followers)模型和半同步/半异步(half-sync/half-async)模型都是常用的客户-服务器编程模型...
查看>>
如何选择行的第一个和最后一个值 之间间隔为5分钟
查看>>
4、QT分析之调试跟踪系统
查看>>
Vmware下Mac系统Vmware tools安装
查看>>
方法多种,选择随已定
查看>>
SharePoint中CAML使用的一些总结
查看>>
Bundle数据传输
查看>>
[Z]POJ 计算几何入门题目推荐[转PKKJ]
查看>>
【每日一摩斯】-Troubleshooting: High CPU Utilization (164768.1) - 系列5
查看>>
Vue.js:轻量高效的前端组件化方案
查看>>
给MySQL增加mysql-udf-http和mysql-udf-json自定义函数,让MySQL有调用http接口和查询直接回JSON的能力...
查看>>
hibernate 单元測试框架
查看>>
Android:关于声明文件中android:process属性说明
查看>>
elastic-job详解(五):自定义任务参数
查看>>
ubuntu设置分辨率
查看>>