我们可以通过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