setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)
setpriority
線程類最終void setPriority(int priority) (Thread Class final void setPriority(int priority))
This method is available in package java.lang.Thread.setPriority(int priority).
軟件包java.lang.Thread.setPriority(int priority)中提供了此方法。
This method is used to set the priority of this thread.
此方法用于設(shè)置此線程的優(yōu)先級。
This method is not static so this method is accessible with Thread class object it is not accessible with the class name.
此方法不是靜態(tài)的,因此該方法可通過Thread類對象訪問,而無法通過類名稱訪問。
This method is final so we can't override this method in our program.
此方法是最終方法,因此我們無法在程序中覆蓋此方法。
The return type of this method is void so it does not return anything.
此方法的返回類型為void,因此它不返回任何內(nèi)容。
This method does not raise any exception.
此方法不會引發(fā)任何異常。
We need to notice that if we don't assign any priority explicitly the default priority of this thread is 5.
我們需要注意的是,如果我們未明確分配任何優(yōu)先級,則此線程的默認(rèn)優(yōu)先級為5。
Priority range will lie between 1 and 10 and 1 is the min_priority and 10 is the max_priority of a thread.
優(yōu)先級范圍在1到10之間,其中1是線程的min_priority ,而10是max_priority 。
Syntax:
句法:
final void setPriority(int priority){}Parameter(s):
參數(shù):
We pass only one object as a parameter in the method of the Thread and the parameter is the priority of this thread too.
我們僅在Thread方法中傳遞一個(gè)對象作為參數(shù),該參數(shù)也是該線程的優(yōu)先級。
Return value:
返回值:
The return type of this method is void, it does not return anything.
此方法的返回類型為void ,它不返回任何內(nèi)容。
Java程序演示setPriority()方法的示例 (Java program to demonstrate example of setPriority() method)
/* We will use Thread class methods so we are importing the package but it is not mandate because it is imported by default */import java.lang.Thread;class SetThreadPriority extends Thread {// Override run() of Thread classpublic void run() {System.out.println("Thread Name : " + Thread.currentThread().getName());System.out.println("Current thread priority is : " + Thread.currentThread().getPriority());// By using setPriority() method is used to change // the priority of this threadThread.currentThread().setPriority(6);System.out.println("New thread priority is : " + Thread.currentThread().getPriority());}public static void main(String[] args) {// Creating an object of SetThreadPriority classSetThreadPriority st_priority = new SetThreadPriority();// We are setting the name of the thread GetThreadPriorityst_priority.setName("SetThreadPriority");// Calling start() method with SetThreadPriority class // object of Thread classst_priority.start();} }Output
輸出量
E:\Programs>javac SetThreadPriority.javaE:\Programs>java SetThreadPriority Thread Name : SetThreadPriority Current thread priority is : 5 New thread priority is : 6翻譯自: https://www.includehelp.com/java/thread-class-final-void-setpriority-int-priority-method-with-example.aspx
setpriority
總結(jié)
以上是生活随笔為你收集整理的setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java ObjectInputStre
- 下一篇: c#中的long类型示例_C#中带示例的