首页 > 编程语言 > 详细

线程优先级的获取及设置

时间:2021-02-24 11:48:52      阅读:29      评论:0      收藏:0      [点我收藏+]

我们可以通过getPriority方法获得线程的优先级,对于主线程,因为它是在main方法里面执行的,不像MyThread那样可以通过对象获取,那么这里先获取线程,再得到它的优先级,来看看代码:

 1 package com.hw.thread0223;
 2 
 3 public class DemoTestThread {
 4     public static void main(String[] args) {
 5         
 6         Thread mainThread = Thread.currentThread();  //获取当前线程
 7         System.out.println("主线程的优先级是:"+mainThread.getPriority());
 8         
 9         MyThread thread = new MyThread();
10         System.out.println("MyThread的优先级是:"+thread.getPriority());
11         thread.start();
12         
13         for(int i = 0;i < 1000;i++)
14         {
15             System.out.println("MyMain:"+i);
16         }
17     }
18 }

技术分享图片

 

线程优先级的获取及设置

原文:https://www.cnblogs.com/EvanTheGreat/p/14440205.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!