org.mmbase.core.util
Class DaemonThread

java.lang.Object
  extended byjava.lang.Thread
      extended byorg.mmbase.core.util.DaemonThread
All Implemented Interfaces:
DaemonTask, Runnable
Direct Known Subclasses:
ModuleProbe

public class DaemonThread
extends Thread
implements DaemonTask

Defines a daemon thread that runs in the threadgroup belonging to this MMBase context.

Since:
MMBase-1.8
Version:
$Id: DaemonThread.java,v 1.2 2005/12/10 11:45:02 michiel Exp $
Author:
Pierre van Rooden

Field Summary
static int DEFAULT_SLEEP_PERIOD
          Default sleep period for a daemon thread (one minute).
protected  int sleepPeriod
          The threads sleep period.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
DaemonThread()
          Create a MMBase daemon thread (associated with this MMBase's threadgroup).
DaemonThread(Runnable target, String name)
          Create a MMBase daemon thread (associated with this MMBase's threadgroup).
DaemonThread(String name)
          Create a MMBase daemon thread (associated with this MMBase's threadgroup).
 
Method Summary
 void executeTask()
          Defines a task that need be run by a daemon thread's run() method.
 int getSleepPeriod()
          Returns this task's sleep period.
 DaemonTask getTask()
          Returns the task this thread runs when started.
 void interrupt()
           
 boolean isRunning()
           
 void run()
          Default behavior (when no target is specified) is to run continuously until interrupted.
 void setTask(DaemonTask task)
          Sets the task this thread should run when started.
 void start()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SLEEP_PERIOD

public static final int DEFAULT_SLEEP_PERIOD
Default sleep period for a daemon thread (one minute).

See Also:
Constant Field Values

sleepPeriod

protected int sleepPeriod
The threads sleep period. This period is used when a Daemonthread runs on its own (that is, without an assigned task) When a DaemonThread is assigned a task, it uses the sleep period of that task.

Constructor Detail

DaemonThread

public DaemonThread()
Create a MMBase daemon thread (associated with this MMBase's threadgroup).


DaemonThread

public DaemonThread(String name)
Create a MMBase daemon thread (associated with this MMBase's threadgroup).

Parameters:
name - the name of the thread

DaemonThread

public DaemonThread(Runnable target,
                    String name)
Create a MMBase daemon thread (associated with this MMBase's threadgroup).

Parameters:
target - the target thread
name - the name of the thread
Method Detail

setTask

public void setTask(DaemonTask task)
Sets the task this thread should run when started.

Parameters:
task - the task to run

getTask

public DaemonTask getTask()
Returns the task this thread runs when started.


getSleepPeriod

public int getSleepPeriod()
Description copied from interface: DaemonTask
Returns this task's sleep period.

Specified by:
getSleepPeriod in interface DaemonTask

start

public void start()

interrupt

public void interrupt()

isRunning

public boolean isRunning()

executeTask

public void executeTask()
Description copied from interface: DaemonTask
Defines a task that need be run by a daemon thread's run() method.

Specified by:
executeTask in interface DaemonTask

run

public void run()
Default behavior (when no target is specified) is to run continuously until interrupted.

Specified by:
run in interface Runnable


MMBase build 1.8.1.20060716