enumerate(Thread[]): This method is available in the java.lang.ThreadGroup class of Java.
Syntax:
int java.lang.ThreadGroup.enumerate(Thread[] list)
This method takes one argument. This method copies into the specified array of every active thread in this thread group and its subgroups.
Parameters: One parameter is required for this method.
list: an array into which to put the list of threads.
Returns: the number of threads put into the array.
Throws:
1. SecurityException - if checkAccess determines that the current thread cannot access this thread group.
Approach
Java
package com.ThreadGroup;public class ThreadGroupenumerate {public static void main(String[] args) {String name = "hello";ThreadGroup threadGroup = new ThreadGroup(name);Thread thread = new Thread();Thread list[] = { thread };System.out.println(threadGroup.enumerate(list));}}
Output:
0
Some other methods of ThreadGroup class
ThreadGroup(String): This method constructs a new thread group. The parent of this new group is the thread group of the currently running thread.
ThreadGroup(ThreadGroup, String): This method creates a new thread group. The parent of this new group is the specified thread group.
activeCount(): This method returns an estimate of the number of active threads in this thread group and its subgroups.
activeGroupCount(): This method returns an estimate of the number of active groups in this thread group and its subgroups. Recursively iterates overall subgroups in this thread group.
checkAccess(): This method determines if the currently running thread has permission to modify this thread group.
destroy(): This method destroys this thread group and all of its subgroups. This thread group must be empty, indicating that all threads that had been in this thread group have since stopped.
enumerate(Thread[]): This method copies into the specified array of every active thread in this thread group and its subgroups.
enumerate(ThreadGroup[]): This method copies into the specified array references to every active subgroup in this thread group and its subgroups.
enumerate(Thread[], boolean): This method copies into the specified array every active thread in this thread group.
enumerate(ThreadGroup[], boolean): This method copies into the specified array of references to every active subgroup in this thread group.
getMaxPriority(): This method returns the maximum priority of this thread group.
getName(): This method returns the name of this thread group.
getParent(): This method returns the parent of this thread group.
interrupt(): This method interrupts all threads in this thread group.
isDaemon(): This method tests if this thread group is a daemon thread group.
isDestroyed(): This method tests if this thread group has been destroyed.
list(): This method prints information about this thread group to the standard output.
parentOf(ThreadGroup): This method tests if this thread group is either the thread group argument or one of its ancestor thread groups.
setDaemon(boolean): This method changes the daemon status of this thread group.
setMaxPriority(int): This method sets the maximum priority of the group. Threads in the thread group that already have a higher priority are not affected.
toString(): This method returns a string representation of this Thread group.
uncaughtException(Thread, Throwable): This method is called by the Java Virtual Machine when a thread in this thread group stops because of an uncaught exception, and the thread does not have a specific Thread.UncaughtExceptionHandlerinstalled.
No comments:
Post a Comment