com.sibvisions.util
Class ThreadHandler

java.lang.Object
  extended by com.sibvisions.util.ThreadHandler

public class ThreadHandler
extends Object

The ThreadHandler manages threads. The threads get a meaningful name and will be stored in an internal list. The handler can stop and start new threads.
It should be used to collect all threads of an application. The access to the thread cache is synchronized.


Constructor Summary
protected ThreadHandler()
          Constructor only for inherited classes, because the ThreadHandler class is a utility class.
 
Method Summary
static boolean add(Thread pThread)
          Adds a thread to the "known" thread list if not already added.
static boolean addIntern(Thread pThread)
          Adds a thread to the "known" thread list if not already added.
static List<Thread> getPendingStoppedThreads()
          Gets all pending stopped threads which are already alive.
static List<Thread> getRunningThreads()
          Gets all "known" and alive threads.
static boolean isStopped()
          Gets if the current thread is stopped.
static boolean isStopped(Thread pThread)
          Gets if a desired thread is stopped.
static void remove(Thread pThread)
          Removes a thread from the "known" thread list.
static Thread start(Runnable pRunnable)
          Starts a thread and adds it to the "known" threads.
static void stop()
          Stops/interrupts all "known" threads.
static Thread stop(Thread pThread)
          Stops/interrupts a thread and removes it from the "known" threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadHandler

protected ThreadHandler()
Constructor only for inherited classes, because the ThreadHandler class is a utility class.

Method Detail

add

public static boolean add(Thread pThread)
Adds a thread to the "known" thread list if not already added. The name of the thread will be extended with the call information of this method. The advantage is that the ThreadHandler can interrupt and list all user-defined threads.

Parameters:
pThread - the thread, which is to be added
Returns:
true if the thread was added, otherwise false

addIntern

public static boolean addIntern(Thread pThread)
Adds a thread to the "known" thread list if not already added.

Parameters:
pThread - the thread, which is to be added
Returns:
true if the thread was added, otherwise false

remove

public static void remove(Thread pThread)
Removes a thread from the "known" thread list.

Parameters:
pThread - the car, which is to be removed

start

public static Thread start(Runnable pRunnable)
Starts a thread and adds it to the "known" threads. The name of the thread will be set to the threads class name and the call information of this method. If a running thread will be startet, the thread will be re

Parameters:
pRunnable - a Thread or another Runnable implementation
Returns:
a new Thread with the pRunnable or pRunnable if it's an instance of Thread and the thread is still alive.
Throws:
IllegalStateException - if the pRunnable is an instance of a finished Thread
See Also:
getRunningThreads()

stop

public static Thread stop(Thread pThread)
Stops/interrupts a thread and removes it from the "known" threads. The stopped thread will be available as pending stop thread.

Parameters:
pThread - the thread, which is to be stopped
Returns:
null
See Also:
getPendingStoppedThreads()

stop

public static void stop()
Stops/interrupts all "known" threads.

See Also:
stop(Thread)

isStopped

public static boolean isStopped()
Gets if the current thread is stopped.

Returns:
true if the current thread is stopped, otherwise false

isStopped

public static boolean isStopped(Thread pThread)
Gets if a desired thread is stopped.

Parameters:
pThread - the thread
Returns:
true if pThread is stopped or pThread == null, otherwise false

getPendingStoppedThreads

public static List<Thread> getPendingStoppedThreads()
Gets all pending stopped threads which are already alive.

Returns:
a list of threads

getRunningThreads

public static List<Thread> getRunningThreads()
Gets all "known" and alive threads.

Returns:
a list of threads


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.