net.sourceforge.groboutils.util.thread.v1
Class TimedProcess
java.lang.Object
net.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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
s_instance
protected static TimedProcess s_instance
REASONABLE_TIME
public static final int REASONABLE_TIME
- See Also:
- Constant Field Values
TimedProcess
protected TimedProcess()
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