日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例

發(fā)布時(shí)間:2025/3/11 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

enumerate

線程類static int枚舉(Thread [] th) (Thread Class static int enumerate(Thread[] th))

  • This method is available in package java.lang.Thread.enumerate(Thread[] th).

    軟件包java.lang.Thread.enumerate(Thread [] th)中提供了此方法。

  • This method is used to copy all the active thread of the current threads thread group or its subgroup into the specified array which will be given as an argument in the method.

    此方法用于將當(dāng)前線程線程組或其子組的所有活動(dòng)線程復(fù)制到指定的數(shù)組中,該數(shù)組將作為方法中的參數(shù)給出。

  • This method is static so this method is accessible with classname too like Thread.enumerate(Thread[] th).

    此方法是靜態(tài)的,因此也可以使用類名訪問(wèn)此方法,例如Thread.enumerate(Thread [] th) 。

  • The return type of this method is int it returns the number of active threads which will be kept in the given array as an argument in the method.

    此方法的返回類型為int,它返回活動(dòng)線程的數(shù)量,該數(shù)量將作為方法的參數(shù)保留在給定數(shù)組中。

  • This method does raise an exception if access permission denies to the thread.

    如果訪問(wèn)權(quán)限拒絕該線程,則此方法會(huì)引發(fā)異常。

Syntax:

句法:

static int enumerate(Thread[] th){}

Parameter(s):

參數(shù):

We pass one array of thread type which will keep all active threads of current threads thread group.

我們傳遞一個(gè)線程類型數(shù)組,該數(shù)組將保留當(dāng)前線程線程組的所有活動(dòng)線程。

Return value:

返回值:

The return type of this method is int, it returns the count of all active threads which will be kept in the array as an argument in the method.

此方法的返回類型為int ,它返回所有活動(dòng)線程的計(jì)數(shù),這些計(jì)數(shù)將作為方法的參數(shù)保留在數(shù)組中。

Java程序演示enumerate()方法的示例 (Java program to demonstrate example of enumerate() 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;public class Enumerate {public static void main(String[] args) {// By using currentThread() of Thread class will return // a reference of currently executing thread.Thread th = Thread.currentThread();// By using setName() method we are setting the name of // current executing threadth.setName("Enumerate Thread");// By using setPriority() method we are setting the // priority of current executing threadth.setPriority(2);//Display Current Executing ThreadSystem.out.println("Currently Executing Thread is :" + th);int active_thread = Thread.activeCount();// Display the number of active threads in current threads thread groupSystem.out.println("The Current active threads is : " + active_thread);Thread[] thread = new Thread[active_thread];// active_thread kept in the arrayThread.enumerate(thread);// Loop for printing active thread if we have more than one thread.for (int i = 0; i < active_thread; ++i)System.out.println("Display active threads is " + thread[i]);} }

Output

輸出量

E:\Programs>javac Enumerate.javaE:\Programs>java Enumerate Currently Executing Thread is :Thread[Enumerate Thread,2,main] The Current active threads is : 1 Display active threads is Thread[Enumerate Thread,2,main]

翻譯自: https://www.includehelp.com/java/thread-class-static-int-enumerate-thread-th-method-with-example.aspx

enumerate

總結(jié)

以上是生活随笔為你收集整理的enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。