Java.lang.Thread.getPriority() 方法
描述
java.lang.Thread.getPriority() 方法返回此线程的优先级。
声明
以下是 java.lang.Thread.getPriority() 方法的声明。
public final int getPriority()
参数
NA
返回值
这个方法返回这个线程的优先级。
异常
NA
示例
下面的例子展示了 java.lang.Thread.getPriority() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class ThreadDemo {
public class ThreadDemo implements Runnable {
Thread t;
ThreadDemo() {
// thread created
t = new Thread(this, "Admin Thread");
// set thread priority
t.setPriority(1);
// print thread created
System.out.println("thread = " + t);
// this will call run() function
t.start();
}
}
public void run() {
// returns this thread's priority.
System.out.println("Thread priority = " + t.getPriority());
}
public static void main(String args[]) {
new ThreadDemo();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
thread = Thread[Admin Thread,1,main] Thread priority = 1

