java.lang.Thread.getPriority()%uA0方法返回当前线程的优先级。
声明
以下是java.lang.Thread.getPriority()方法的声明
public final int getPriority()
参数
-
NA
返回值
此方法返回该线程的优先级。
异常
-
NA
例子
下面的例子显示java.lang.Thread.getPriority()方法的使用。
package com.yiibai 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&aposs 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