JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit
Class ThreadTools

java.lang.Object
  |
  +--com.jthreadkit.ThreadTools

public class ThreadTools
extends Object

PrintStream* Contains some handy constants and methods for use with JThreadKit.


Field Summary
static long NO_TIMEOUT
          Used to hold the long value 0L for the "wait forever" timeout.
static String VERSION
          The string representation of the version number for this version of JThreadKit.
 
Method Summary
static void execute(Runnable workBundle)
          Runs the specified bundle of work asynchronously using another thread.
static String getVersion()
          Returns the version number of JThreadKit.
static void join(Thread threadToWaitFor, long msTimeout)
          The calling thread waits (up to the specified timeout) for the specified thread to die.
static boolean join(Thread threadToWaitFor, long msTimeout, boolean useTimedOutException)
          The calling thread waits (up to the specified timeout) for the specified thread to die.
static void print(String msg)
          Prefixes the specified message with the name of the thread and prints the resulting line to the specified System.out.
static void printErr(String msg)
          Prefixes the specified message with the name of the thread and prints the resulting line to the specified System.err.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final String VERSION
The string representation of the version number for this version of JThreadKit.

NO_TIMEOUT

public static final long NO_TIMEOUT
Used to hold the long value 0L for the "wait forever" timeout. When this value is passed for a timeout value, the waiting will not timeout.
Method Detail

print

public static void print(String msg)
Prefixes the specified message with the name of the thread and prints the resulting line to the specified System.out. This can be a useful tool for illustrative or debugging purposes.

printErr

public static void printErr(String msg)
Prefixes the specified message with the name of the thread and prints the resulting line to the specified System.err. This can be a useful tool for illustrative or debugging purposes.

getVersion

public static final String getVersion()
Returns the version number of JThreadKit.

join

public static boolean join(Thread threadToWaitFor,
                           long msTimeout,
                           boolean useTimedOutException)
                    throws InterruptedException,
                           TimedOutException,
                           IllegalArgumentException
The calling thread waits (up to the specified timeout) for the specified thread to die. If a timeout occurs, either false is returned or a TimedOutException is thrown. Which occurs depends on whether an exception was requested by passing true for the third parameter: useTimedOutException. If the specified thread does die within the timeout period, true is returned.
Parameters:
threadToWaitFor - the thread to wait on while still alive.
msTimeout - the maximum number of milliseconds to wait for threadToWaitFor to die. Must be greater than 0 or else an IllegalArgumentException is thrown (ThreadTools.NO_TIMEOUT can not be passed, if you can to wait forever, see the join() method on Thread).
useTimedOutException - if true and a timeout occurs, a TimedOutException will be thrown. If false and a timeout occurs, this method returns false.
Returns:
true if the specified thread dies within the timeout period, or false if a timeout occurred.
Throws:
InterruptedException - if the calling thread is interrupted while waiting for the specified thread to die.
TimedOutException - if useTimedOutException is true and a timeout occurs.
IllegalArgumentException - if msTimeout is less than 1.

join

public static void join(Thread threadToWaitFor,
                        long msTimeout)
                 throws InterruptedException,
                        TimedOutException,
                        IllegalArgumentException
The calling thread waits (up to the specified timeout) for the specified thread to die. If a timeout occurs while waiting, a TimedOutException is thrown, otherwise the method just returns.
Parameters:
threadToWaitFor - the thread to wait on while still alive.
msTimeout - the maximum number of milliseconds to wait for threadToWaitFor to die. Must be greater than 0 or else an IllegalArgumentException is thrown (ThreadTools.NO_TIMEOUT can not be passed, if you can to wait forever, see the join() method on Thread).
Throws:
InterruptedException - if the calling thread is interrupted while waiting for the specified thread to die.
TimedOutException - if the timeout period expires before the specified thread dies.
IllegalArgumentException - if msTimeout is less than 1.

execute

public static void execute(Runnable workBundle)
Runs the specified bundle of work asynchronously using another thread. A thread is borrowed from the shared static instance of BottomlessThreadPool to run the task. Since the pool is "bottomless", the task will always get a thread to run it (up to the limits of the VM of course!).

When this method returns, the run() method of the workBundle may or may not have already been called by the helper thread--you can't count on either case.

Parameters:
workBundle - the Runnable to pass off to the helper thread.

JThreadKitTM
v1.1.0
(public members only)

© Copyright 2000-2001 Programix Incorporated. All rights reserved. JThreadKit home