Class Daemon

java.lang.Object
org.simpleframework.common.thread.Daemon
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ActionDistributor, LeaseCleaner, ServerCleaner

public abstract class Daemon extends Object implements Runnable
The Daemon object provides a named thread which will execute the run method when started. This offers some convenience in that it hides the normal thread methods and also allows the object extending this to provide the name of the internal thread, which is given an incrementing sequence number appended to the name provided.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
    The RunnableDelegate object is used to actually invoke the run method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final AtomicBoolean
    This is used to determine if the daemon is active.
    private final Runnable
    This is the internal thread that is executed by this.
    private final DaemonFactory
    This is the internal thread used by this daemon instance.
    private final AtomicReference<Thread>
    This is the current thread executing this service.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for the Daemon object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to interrupt the internal thread.
    boolean
    This is used to determine if the runner is active.
    void
    This is used to start the internal thread.
    void
    This method is used to stop the thread without forcing it to stop.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Runnable

    run
  • Field Details

    • reference

      private final AtomicReference<Thread> reference
      This is the current thread executing this service.
    • factory

      private final DaemonFactory factory
      This is the internal thread used by this daemon instance.
    • active

      private final AtomicBoolean active
      This is used to determine if the daemon is active.
    • delegate

      private final Runnable delegate
      This is the internal thread that is executed by this.
  • Constructor Details

    • Daemon

      protected Daemon()
      Constructor for the Daemon object. This will create the internal thread and ensure it is a daemon. When it is started the name of the internal thread is set using the name of the instance as taken from getName. If the name provided is null then no name is set for the thread.
  • Method Details

    • isActive

      public boolean isActive()
      This is used to determine if the runner is active. If it is not active then it is assumed that no thread is executing. Also, if this is extended then any executing thread to stop as soon as this method returns false.
      Returns:
      this returns true if the runner is active
    • start

      public void start()
      This is used to start the internal thread. Once started the internal thread will execute the run method of this instance. Aside from starting the thread this will also ensure the internal thread has a unique name.
    • interrupt

      public void interrupt()
      This is used to interrupt the internal thread. This is used when there is a need to wake the thread from a sleeping or waiting state so that some other operation can be performed. Typically this is required when killing the thread.
    • stop

      public void stop()
      This method is used to stop the thread without forcing it to stop. It acts as a means to deactivate it. It is up to the implementor to ensure that the isActive method is checked to determine whether it should continue to run.