Package org.apache.wiki
Class WikiBackgroundThread
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.wiki.WikiBackgroundThread
-
- All Implemented Interfaces:
java.lang.Runnable
,java.util.EventListener
,WikiEventListener
- Direct Known Subclasses:
RSSThread
public abstract class WikiBackgroundThread extends java.lang.Thread implements WikiEventListener
Abstract Thread subclass that operates in the background; when it detects theWikiEngineEvent.SHUTDOWN
event, it terminates itself. Subclasses of this method need only implement the methodbackgroundTask()
, instead of the normalThread.run()
, and provide a constructor that passes the Engine and sleep interval. This class is thread-safe.
-
-
Constructor Summary
Constructors Constructor Description WikiBackgroundThread(Engine engine, int sleepInterval)
Constructs a new instance of this background thread with a specified sleep interval, and adds the new instance to the wiki engine's event listeners.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(WikiEvent event)
Listens forWikiEngineEvent.SHUTDOWN
and, if detected, marks the thread for death.abstract void
backgroundTask()
Abstract method that performs the actual work for this background thread; subclasses must implement this method.Engine
getEngine()
Returns the Engine that created this background thread.void
run()
Runs the background thread'sbackgroundTask()
method at the interval specified at construction.void
shutdown()
Requests the shutdown of this background thread.void
shutdownTask()
Executes a task after shutdown signal was detected.void
startupTask()
Executes a task just after the thread'sThread.run()
method starts, but before thebackgroundTask()
task executes.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Constructor Detail
-
WikiBackgroundThread
public WikiBackgroundThread(Engine engine, int sleepInterval)
Constructs a new instance of this background thread with a specified sleep interval, and adds the new instance to the wiki engine's event listeners.- Parameters:
engine
- the wiki enginesleepInterval
- the interval between invocations of the thread'sThread.run()
method, in seconds
-
-
Method Detail
-
actionPerformed
public final void actionPerformed(WikiEvent event)
Listens forWikiEngineEvent.SHUTDOWN
and, if detected, marks the thread for death.- Specified by:
actionPerformed
in interfaceWikiEventListener
- Parameters:
event
- a WikiEvent object- See Also:
WikiEventListener.actionPerformed(org.apache.wiki.event.WikiEvent)
-
backgroundTask
public abstract void backgroundTask() throws java.lang.Exception
Abstract method that performs the actual work for this background thread; subclasses must implement this method.- Throws:
java.lang.Exception
- Any exception can be thrown
-
getEngine
public Engine getEngine()
Returns the Engine that created this background thread.- Returns:
- the wiki engine
-
shutdown
public void shutdown()
Requests the shutdown of this background thread. Note that the shutdown is not immediate.- Since:
- 2.4.92
-
run
public final void run()
Runs the background thread'sbackgroundTask()
method at the interval specified at construction. The thread will initially pause for a full sleep interval before starting, after which it will executestartupTask()
. This method will cleanly terminate the thread if it has previously been marked as dead, before which it will executeshutdownTask()
. If any of the three methods return an exception, it will be re-thrown as aInternalWikiException
.- Specified by:
run
in interfacejava.lang.Runnable
- Overrides:
run
in classjava.lang.Thread
- See Also:
Thread.run()
-
shutdownTask
public void shutdownTask() throws java.lang.Exception
Executes a task after shutdown signal was detected. By default, this method does nothing; override it to implement custom functionality.- Throws:
java.lang.Exception
- Any exception can be thrown.
-
startupTask
public void startupTask() throws java.lang.Exception
Executes a task just after the thread'sThread.run()
method starts, but before thebackgroundTask()
task executes. By default, this method does nothing; override it to implement custom functionality.- Throws:
java.lang.Exception
- Any exception can be thrown.
-
-