Package ch.k43.util

Klasse KThread

java.lang.Object
java.lang.Thread
ch.k43.util.KThread
Alle implementierten Schnittstellen:
Runnable
Bekannte direkte Unterklassen:
KLogSMTPHandlerThread

public abstract class KThread extends Thread
This class adds some convenient methods for starting and stopping Java threads.
  Example: Start/stop thread
  
  // Create thread and call kStart() method
  KThread thread = new TestThread();
  ...
  
  // Signal termination and send interrupt to thread 
  thread.kStop();
  
  Example: User thread
  public class TestThread extends KThread {
  
        public TestThread() {
                        ...
        }
  
        public void kStart() {
                        ...
                        // Run until kStop() is called 
                        while (!kMustTerminate()) {
                        ...
                        }
        }
  
        public synchronized void kCleanup() {
                        // Do any resource cleanup (will be called automatically)
        }
  }
  
Seit:
2024.09.06
  • Methodendetails

    • kCleanup

      public void kCleanup()
      Cleanup method called by run() just before termination.
    • kMustTerminate

      public final boolean kMustTerminate()
      Check if thread should be terminated.
      Gibt zurück:
      True (if kStop() was called previously), false otherwise
      Siehe auch:
    • kStart

      public abstract void kStart()
      Main entry point for user thread. This method must be implemented by the subclass.
    • kStop

      public final void kStop()
      Set the thread termination flag and interrupt the thread.
    • kStop

      public final void kStop(boolean argInterrupt)
      Set the thread termination flag and optionally send interrupt to the thread.
      Parameter:
      argInterrupt - Send interrupt signal to thread
    • run

      public final void run()
      Start thread by calling method kStart(). After kStart() returns, the method kCleanup() is automatically called to allow for any resource cleanup by the user thread.
      Angegeben von:
      run in Schnittstelle Runnable
      Setzt außer Kraft:
      run in Klasse Thread
    • start

      public final void start()
      Prohibit overwriting.
      Setzt außer Kraft:
      start in Klasse Thread
    • toString

      public String toString()
      Output object data.
      Setzt außer Kraft:
      toString in Klasse Thread