com.calitha.util
Class CleanupThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.calitha.util.CleanupThread
All Implemented Interfaces:
Runnable

public class CleanupThread
extends Thread

A CleaupThread object represents a thread that helps to for clean up resources in your application on a regular basis. The thread does not do the actual cleanup jobs, but holds a list of cleanable objects and calls the cleanup jobs.

Author:
Robert van Loenhout

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
CleanupThread(long interval)
          Creates a new cleanup thread.
 
Method Summary
 void add(ICleanable object)
          Adds a cleanable object that is periodically called to clean itself.
protected  void cleanupAll()
          Let the cleanable objects do their jobs.
 void run()
          Executed when the thread is started.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CleanupThread

public CleanupThread(long interval)
Creates a new cleanup thread.

Parameters:
interval - the interval in seconds between cleanup jobs
Method Detail

add

public void add(ICleanable object)
Adds a cleanable object that is periodically called to clean itself.

Parameters:
object - cleanable object
Throws:
IllegalArgumentException - if an argument is null

cleanupAll

protected void cleanupAll()
Let the cleanable objects do their jobs.


run

public void run()
Executed when the thread is started.

Specified by:
run in interface Runnable
Overrides:
run in class Thread