org.apache.tapestry.util
Class JanitorThread
java.lang.Object
|
+--java.lang.Thread
|
+--org.apache.tapestry.util.JanitorThread
- All Implemented Interfaces:
- Runnable
- public class JanitorThread
- extends Thread
A basic kind of janitor, an object that periodically invokes
ICleanable.executeCleanup()
on a set of objects.
The JanitorThread holds a weak reference to
the objects it operates on.
- Since:
- 1.0.5
- Version:
- $Id: JanitorThread.java,v 1.2 2003/05/28 13:41:43 hlship Exp $
- Author:
- Howard Lewis Ship
Field Summary |
static long |
DEFAULT_INTERVAL_MILLIS
Default number of seconds between janitor runs, about 30 seconds. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield |
DEFAULT_INTERVAL_MILLIS
public static final long DEFAULT_INTERVAL_MILLIS
- Default number of seconds between janitor runs, about 30 seconds.
JanitorThread
public JanitorThread()
- Creates a new daemon Janitor.
JanitorThread
public JanitorThread(String name)
- Creates new Janitor with the given name. The thread
will have minimum priority and be a daemon.
getSharedJanitorThread
public static JanitorThread getSharedJanitorThread()
- Returns a shared instance of JanitorThread. In most cases,
the shared instance should be used, rather than creating
a new instance; the exception being when particular
scheduling is of concern. It is also bad policy to
change the sleep interval on the shared janitor
(though nothing prevents this, either).
getInterval
public long getInterval()
setInterval
public void setInterval(long value)
- Updates the property, then interrupts the thread.
- Parameters:
the
- interval, in milliseconds, between sweeps.- Throws:
IllegalStateException
- always, if the receiver is the shared JanitorThreadIllegalArgumentException
- if value is less than 1
add
public void add(ICleanable cleanable)
- Adds a new cleanable object to the list of references. Care should be taken that
objects are not added multiple times; they will be
cleaned too often.
sweep
protected void sweep()
- Runs through the list of targets and invokes
ICleanable.executeCleanup()
on each of them. WeakReference
s that have been invalidated
are weeded out.
waitForNextPass
protected void waitForNextPass()
- Waits for the next run, by sleeping for the desired period.
run
public void run()
- Alternates between
waitForNextPass()
and
sweep()
.
- Overrides:
run
in class Thread
toString
public String toString()
- Overrides:
toString
in class Thread