日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)

發布時間:2025/3/11 java 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.

    此方法用于設置此線程的優先級。

  • This method is not static so this method is accessible with Thread class object it is not accessible with the class name.

    此方法不是靜態的,因此該方法可通過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,因此它不返回任何內容。

  • This method does not raise any exception.

    此方法不會引發任何異常。

  • We need to notice that if we don't assign any priority explicitly the default priority of this thread is 5.

    我們需要注意的是,如果我們未明確分配任何優先級,則此線程的默認優先級為5。

  • Priority range will lie between 1 and 10 and 1 is the min_priority and 10 is the max_priority of a thread.

    優先級范圍在1到10之間,其中1是線程的min_priority ,而10是max_priority 。

Syntax:

句法:

final void setPriority(int priority){}

Parameter(s):

參數:

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方法中傳遞一個對象作為參數,該參數也是該線程的優先級。

Return value:

返回值:

The return type of this method is void, it does not return anything.

此方法的返回類型為void ,它不返回任何內容。

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

總結

以上是生活随笔為你收集整理的setpriority_Java Thread类的最终void setPriority(int priority)方法(带示例)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。