public abstract class WikiBackgroundThread extends java.lang.Thread implements WikiEventListener
WikiEngineEvent.SHUTDOWN event,
it terminates itself. Subclasses of this method need only implement the method backgroundTask(), instead of
the normal Thread.run(), and provide a constructor that passes the Engine and sleep interval. This class is thread-safe.| Constructor and 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.
|
| Modifier and Type | Method and Description |
|---|---|
void |
actionPerformed(WikiEvent event)
Listens for
WikiEngineEvent.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's
backgroundTask() 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's
Thread.run() method starts, but before the backgroundTask() task executes. |
activeCount, checkAccess, clone, 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, yieldpublic WikiBackgroundThread(Engine engine, int sleepInterval)
engine - the wiki enginesleepInterval - the interval between invocations of
the thread's Thread.run() method, in secondspublic final void actionPerformed(WikiEvent event)
WikiEngineEvent.SHUTDOWN and, if detected, marks the thread for death.actionPerformed in interface WikiEventListenerevent - WikiEventListener.actionPerformed(org.apache.wiki.event.WikiEvent)public abstract void backgroundTask() throws java.lang.Exception
java.lang.Exception - Any exception can be thrownpublic Engine getEngine()
public void shutdown()
public final void run()
backgroundTask() method at the interval specified at construction.
The thread will initially pause for a full sleep interval before starting, after which it will execute
startupTask(). This method will cleanly terminate the thread if it has previously been marked as
dead, before which it will execute shutdownTask(). If any of the three methods return an exception,
it will be re-thrown as a InternalWikiException.run in interface java.lang.Runnablerun in class java.lang.ThreadThread.run()public void shutdownTask() throws java.lang.Exception
java.lang.Exception - Any exception can be thrown.public void startupTask() throws java.lang.Exception
Thread.run() method starts, but before the backgroundTask() task executes.
By default, this method does nothing; override it to implement custom functionality.java.lang.Exception - Any exception can be thrown.Copyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.