enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例
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.
此方法用于將當前線程線程組或其子組的所有活動線程復制到指定的數組中,該數組將作為方法中的參數給出。
This method is static so this method is accessible with classname too like Thread.enumerate(Thread[] th).
此方法是靜態的,因此也可以使用類名訪問此方法,例如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,它返回活動線程的數量,該數量將作為方法的參數保留在給定數組中。
This method does raise an exception if access permission denies to the thread.
如果訪問權限拒絕該線程,則此方法會引發異常。
Syntax:
句法:
static int enumerate(Thread[] th){}Parameter(s):
參數:
We pass one array of thread type which will keep all active threads of current threads thread group.
我們傳遞一個線程類型數組,該數組將保留當前線程線程組的所有活動線程。
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 ,它返回所有活動線程的計數,這些計數將作為方法的參數保留在數組中。
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
總結
以上是生活随笔為你收集整理的enumerate_Java Thread类的static int enumerate(Thread [] th)方法与示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: getsimplename_Java类类
- 下一篇: ruby 数组元素替换_从Ruby中的集