ProgramixGenericLib v5.0.1

com.programix.thread
Class ThreadTools

java.lang.Object
  extended by com.programix.thread.ThreadTools

public class ThreadTools
extends Object

Handy and commonly used tools for working with multithreaded code.

For advanced tools and utilities related to multithreading, please check out JThreadKit.

Author:
Paul Hyde

Field Summary
static long NO_TIMEOUT
          Indicates that the 'waiting' should not time out (no matter how much time elapses).
static boolean SUCCESS
          Signals that the attempted operation was successful.
static boolean TIMED_OUT
          Signals that the attempted operation ran out of time.
 
Method Summary
static void nap(long msDuration)
          Causes the calling thread to go to sleep for the specified amount of time.
static void napRandom(long msMinDuration, long msMaxDuration)
          Causes the calling thread to go to sleep for a random amount of time in the specified range of time.
static void out(Object msg)
          Prints the specified message prefixed with the elapsed time and the name of the calling thread.
static void outln(Object msg)
          Prints the specified message prefixed with the elapsed time and the name of the calling thread.
static void println(Object message)
          Prints the specified message prefixed with the name of the calling thread to System.out.println (standard out).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_TIMEOUT

public static final long NO_TIMEOUT
Indicates that the 'waiting' should not time out (no matter how much time elapses).

See Also:
Constant Field Values

SUCCESS

public static final boolean SUCCESS
Signals that the attempted operation was successful.

See Also:
Constant Field Values

TIMED_OUT

public static final boolean TIMED_OUT
Signals that the attempted operation ran out of time.

See Also:
Constant Field Values
Method Detail

println

public static void println(Object message)
Prints the specified message prefixed with the name of the calling thread to System.out.println (standard out).

Parameters:
message - the message to print printed.

out

public static void out(Object msg)
Prints the specified message prefixed with the elapsed time and the name of the calling thread. The message is printed to the console using a single LineLogger held by ThreadTools (if you need more flexibility, then use LineLogger directly).


outln

public static void outln(Object msg)
Prints the specified message prefixed with the elapsed time and the name of the calling thread. The message is printed to the console using a single LineLogger held by ThreadTools (if you need more flexibility, then use LineLogger directly).


nap

public static void nap(long msDuration)
                throws InterruptException
Causes the calling thread to go to sleep for the specified amount of time. If the calling thread is interrupted while sleeping, an InterruptException is thrown (note that this is a RuntimeException so callers are not required to catch it).

Parameters:
msDuration - the number of milliseconds to sleep for.
Throws:
InterruptException - if the nap is interrupted.

napRandom

public static void napRandom(long msMinDuration,
                             long msMaxDuration)
                      throws InterruptException
Causes the calling thread to go to sleep for a random amount of time in the specified range of time. If the calling thread is interrupted while sleeping, an InterruptException is thrown (note that this is a RuntimeException so callers are not required to catch it).

Parameters:
msMinDuration - the minimum number of milliseconds to sleep for.
msMaxDuration - the maximum number of milliseconds to sleep for.
Throws:
InterruptException - if the nap is interrupted.

ProgramixGenericLib v5.0.1

Copyright © 2001-2009 Programix Incorporated. All rights reserved. ProgramixGenericLib is free and is OSI Certified Open Source Software under the BSD license.