java.lang.Object
org.cybergarage.util.ThreadCore
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
Advertiser, Disposer, RenewSubscriber

public class ThreadCoreextends Object implements Runnable
Base class for managing thread lifecycle and execution. This class implements Runnable and provides methods to start, stop, restart, and manage thread execution in a safe manner using thread interruption.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Thread
    /////////////////////////////////////////////
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new ThreadCore instance.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    Gets the internal Thread object.
    boolean
    Checks if the current thread is the same as this ThreadCore's thread.
    void
    Restarts the thread by stopping it first and then starting it again.
    void
    run()
    The main execution method of the thread.
    void
    Sets the internal Thread object.
    void
    Starts the thread if it's not already running.
    void
    Stops the thread safely using interruption.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mThreadObject

      private Thread mThreadObject
      /////////////////////////////////////////////
  • Constructor Details

    • ThreadCore

      public ThreadCore()
      Creates a new ThreadCore instance.
  • Method Details

    • setThreadObject

      public void setThreadObject(Thread obj)
      Sets the internal Thread object.
      Parameters:
      obj - the Thread object to set
    • getThreadObject

      public Thread getThreadObject()
      Gets the internal Thread object.
      Returns:
      the Thread object, or null if not set
    • start

      public void start()
      Starts the thread if it's not already running. Creates a new Thread object if one doesn't exist.
    • run

      public void run()
      The main execution method of the thread. This method should be overridden by subclasses to implement specific functionality.
      Specified by:
      run in interface Runnable
    • isRunnable

      public boolean isRunnable()
      Checks if the current thread is the same as this ThreadCore's thread.
      Returns:
      true if the current thread is running this ThreadCore, false otherwise
    • stop

      public void stop()
      Stops the thread safely using interruption. This method interrupts the thread and clears the thread object reference.
    • restart

      public void restart()
      Restarts the thread by stopping it first and then starting it again.