com.sibvisions.util
Class ThreadManager

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

public class ThreadManager
extends java.lang.Object

The ThreadManager manages threads. The threads get a meaningful name and will be stored in an internal list. The manager 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
ThreadManager()
          Creates a new instance of ThreadManager.
 
Method Summary
 boolean add(java.lang.Thread pThread)
          Adds a thread to the "known" thread list if not already added.
 java.util.List<java.lang.Thread> getPendingStoppedThreads()
          Gets all pending stopped threads which are already alive.
 java.util.List<java.lang.Thread> getRunningThreads()
          Gets all "known" and alive threads.
 boolean isStopped()
          Gets if the current thread is stopped.
 boolean isStopped(java.lang.Thread pThread)
          Gets if a desired thread is stopped.
 void remove(java.lang.Thread pThread)
          Removes a thread from the "known" thread list.
 java.lang.Thread start(java.lang.Runnable pRunnable)
          Starts a thread and adds it to the "known" threads.
 void stop()
          Stops/interrupts all "known" threads.
 java.lang.Thread stop(java.lang.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

ThreadManager

public ThreadManager()
Creates a new instance of ThreadManager.

Method Detail

add

public boolean add(java.lang.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

remove

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

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

start

public java.lang.Thread start(java.lang.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:
java.lang.IllegalStateException - if the pRunnable is an instance of a finished Thread
See Also:
getRunningThreads()

stop

public java.lang.Thread stop(java.lang.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 void stop()
Stops/interrupts all "known" threads.

See Also:
stop(Thread)

isStopped

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

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

isStopped

public boolean isStopped(java.lang.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 java.util.List<java.lang.Thread> getPendingStoppedThreads()
Gets all pending stopped threads which are already alive.

Returns:
a list of threads

getRunningThreads

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

Returns:
a list of threads


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.