net.sourceforge.groboutils.util.thread.v1
Class TimedProcess

java.lang.Object
  extended bynet.sourceforge.groboutils.util.thread.v1.TimedProcess

public class TimedProcess
extends java.lang.Object

A Utility to run a task in a thread, and to kill it if the thread runs too long. This will first attempt an interrupt() on the thread. If that doesn't work, then a stop() will be executed. This is a well-documented bad practice, so you have been warned!

Since:
15-Mar-2002
Version:
$Date: 2003/02/10 22:52:49 $
Author:
Matt Albrecht groboclown@users.sourceforge.net

Nested Class Summary
static interface TimedProcess.RunnableKiller
          Implement this interface to have your own method for killing the runner and thread.
 
Field Summary
static int REASONABLE_TIME
           
protected static TimedProcess s_instance
           
 
Constructor Summary
protected TimedProcess()
           
 
Method Summary
static TimedProcess getInstance()
           
protected  void joinThread(java.lang.Thread t, long joinTime)
           
 void runTimed(java.lang.Runnable process, long waitTimeMillis)
          Runs the given process in a Thread.
 void runTimed(java.lang.Runnable process, long waitTimeMillis, TimedProcess.RunnableKiller processEnder)
          Runs the given process in a Thread.
protected  void setupThread(java.lang.Thread t)
           
protected  void stopThread(java.lang.Thread t, java.lang.Runnable process, TimedProcess.RunnableKiller processEnder)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

s_instance

protected static TimedProcess s_instance

REASONABLE_TIME

public static final int REASONABLE_TIME
See Also:
Constant Field Values
Constructor Detail

TimedProcess

protected TimedProcess()
Method Detail

getInstance

public static TimedProcess getInstance()

runTimed

public void runTimed(java.lang.Runnable process,
                     long waitTimeMillis)
              throws java.lang.InterruptedException
Runs the given process in a Thread. If it does not stop within the specified time, then attempts will be made to kill the thread (see earlier text). If the process did not complete in the specified time, an InterruptedException will be thrown.

Throws:
java.lang.InterruptedException - if the process did not complete within the given time frame.

runTimed

public void runTimed(java.lang.Runnable process,
                     long waitTimeMillis,
                     TimedProcess.RunnableKiller processEnder)
              throws java.lang.InterruptedException
Runs the given process in a Thread. If it does not stop within the specified time, then attempts will be made to kill the thread (see earlier text). If the process did not complete in the specified time, an InterruptedException will be thrown.

Throws:
java.lang.InterruptedException - if the process did not complete within the given time frame.

setupThread

protected void setupThread(java.lang.Thread t)

stopThread

protected void stopThread(java.lang.Thread t,
                          java.lang.Runnable process,
                          TimedProcess.RunnableKiller processEnder)

joinThread

protected void joinThread(java.lang.Thread t,
                          long joinTime)


Copyright © 2001-2003 by The GroboUtils Project