Class PThread

java.lang.Object
java.lang.Thread
com.dkt.graphics.utils.PThread
All Implemented Interfaces:
Runnable

public abstract class PThread extends Thread
This class basically implements a pausable thread. Please note that the pause() and unpause() methods won't release any of the locks the thread might hold, it will simply pause the thread.
Author:
Federico Vera <[email protected]>
  • Constructor Details

    • PThread

      public PThread()
  • Method Details

    • pause

      public final boolean pause()
      Pauses the current thread
      Returns:
      true if the thread was successfully paused and false if the thread was already paused
    • unpause

      public final void unpause()
      Resumes the current thread
    • checkPause

      protected final void checkPause()
      This method should be called within the main run loop. If this isn't called then the thread will not be paused. An example of an implementation could be:
            class MyThread extends PThread {
                @Override
                public void run() {
                    //Init code
                    while(!interrupted() && condition){
                         checkPause();
                         //Loop code
                    }
                    //End code
                }
            }
       
    • run

      public abstract void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread