com.kuka.common
Class ThreadUtil

java.lang.Object
  extended by com.kuka.common.ThreadUtil

public final class ThreadUtil
extends Object

Helper class for threads.


Method Summary
static void dumpThreadGroup(OutputStream out, ThreadGroup group)
          Tries to dump all child threads and thread groups of the given ThreadGroup.
static void dumpThreadGroup(Writer writer, ThreadGroup group)
          Tries to dump all child threads and thread groups of the given ThreadGroup.
static List<ThreadGroup> getActiveThreadGroups(ThreadGroup group)
          Returns the active thread groups in the given ThreadGroup.
static List<Thread> getActiveThreads(ThreadGroup group, boolean daemon)
          Returns the active normal or daemon threads in the given ThreadGroup.
static ThreadGroup getMainThreadGroup()
           
static int getThreadCount(ThreadGroup group, boolean daemon)
          Returns the number of active normal or daemon threads in the given ThreadGroup.
static void milliSleep(long millis)
          Helper method for sleeping some time.
static void nanoSleep(long nanoSeconds)
          Helper method for sleeping some time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

milliSleep

public static void milliSleep(long millis)
Helper method for sleeping some time.

Catches the interrupted exception, 'reinterrupts' the thread so that it's isInterrupted method returns true and throws a ThreadInterruptedException.

Following calls of ThreadUtil.milliSleep() and ThreadUtil.nanoSleep() will return immediately in case the interrupted exception has been thrown previously.

Parameters:
millis - The milliseconds to sleep. If negative or 0, the method returns immediately.
Throws:
ThreadInterruptedException - if the sleep was interrupted.

nanoSleep

public static void nanoSleep(long nanoSeconds)
Helper method for sleeping some time.

Catches the interrupted exception, 'reinterrupts' the thread so that it's isInterrupted method returns true and throws a ThreadInterruptedException.

Following calls of ThreadUtil.milliSleep() and ThreadUtil.nanoSleep() will return immediately in case the interrupted exception has been thrown previously.

Parameters:
nanoSeconds - The nanoseconds to sleep. If negative or 0, the method returns immediately.
Throws:
ThreadInterruptedException - if the sleep was interrupted.

getThreadCount

public static int getThreadCount(ThreadGroup group,
                                 boolean daemon)
Returns the number of active normal or daemon threads in the given ThreadGroup.

Parameters:
group - the thread group
daemon - true, if the number of daemon threads
Returns:
the number of active threads

getActiveThreads

public static List<Thread> getActiveThreads(ThreadGroup group,
                                            boolean daemon)
Returns the active normal or daemon threads in the given ThreadGroup.

Parameters:
group - the thread group
daemon - true if daemon threads
Returns:
the active threads

getActiveThreadGroups

public static List<ThreadGroup> getActiveThreadGroups(ThreadGroup group)
Returns the active thread groups in the given ThreadGroup.

Parameters:
group - the thread group
Returns:
the active thread groups

dumpThreadGroup

public static void dumpThreadGroup(OutputStream out,
                                   ThreadGroup group)
Tries to dump all child threads and thread groups of the given ThreadGroup. This is not guaranteed to print all threads, see the comment for ThreadGroup.enumerate(Thread[]).

Parameters:
out - An OutputStream, for example System.out. The default character encoding will be used.
group - the thread group to dump

dumpThreadGroup

public static void dumpThreadGroup(Writer writer,
                                   ThreadGroup group)
Tries to dump all child threads and thread groups of the given ThreadGroup. This is not guaranteed to print all threads, see the comment for ThreadGroup.enumerate(Thread[]).

Parameters:
writer - A Writer, for example a StringWriter.
group - the thread group to dump

getMainThreadGroup

public static ThreadGroup getMainThreadGroup()
Returns:
the main thread group of the current java process.


Copyright © 2019. All rights reserved.