Class GentleThread

  • All Implemented Interfaces:
    java.lang.Runnable

    public abstract class GentleThread
    extends java.lang.Thread
    an abstract Thread class that provides utilities for easily defining Threads with safe versions of the deprecated thread methods stop(), resume(), and start()
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.lang.Thread

        java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
    • Field Summary

      • Fields inherited from class java.lang.Thread

        MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected void allowSuspend()
      tests whether the thread should suspend, and causes to the thread to pause if appropriate.
      void gentleResume()
      a safe method for resuming properly implemented GentleThreads
      void gentleStop()
      a safe method for stopping properly implemented GentleThreads
      void gentleSuspend()
      a safe method for suspending properly implemented GentleThreads
      abstract void run()  
      protected boolean shouldStop()
      tests whether the thread should stop.
      protected boolean shouldSuspend()
      tests whether the thread should suspend.
      • Methods inherited from class java.lang.Thread

        activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GentleThread

        public GentleThread()
      • GentleThread

        public GentleThread​(java.lang.String name)
    • Method Detail

      • run

        public abstract void run()
        Specified by:
        run in interface java.lang.Runnable
        Overrides:
        run in class java.lang.Thread
      • gentleStop

        public void gentleStop()
        a safe method for stopping properly implemented GentleThreads
      • gentleSuspend

        public void gentleSuspend()
        a safe method for suspending properly implemented GentleThreads
      • gentleResume

        public void gentleResume()
        a safe method for resuming properly implemented GentleThreads
      • shouldStop

        protected boolean shouldStop()
        tests whether the thread should stop. Subclasses should call this method periodically in their run method, and return from run() is the method returns true.
      • shouldSuspend

        protected boolean shouldSuspend()
        tests whether the thread should suspend. Subclasses rarely call this method directly, and should call allowSuspend() periodically instead.
        See Also:
        allowSuspend()
      • allowSuspend

        protected void allowSuspend()
                             throws java.lang.InterruptedException
        tests whether the thread should suspend, and causes to the thread to pause if appropriate. Subclasses should call this method periodically in their run method to, um, allow suspension. Threads paused by allowSuspend() will be properly awoken by gentleResume()
        Throws:
        java.lang.InterruptedException
        See Also:
        gentleResume()