Package ch.k43.util
Klasse KThread
java.lang.Object
java.lang.Thread
ch.k43.util.KThread
- Alle implementierten Schnittstellen:
Runnable
- Bekannte direkte Unterklassen:
KLogSMTPHandlerThread
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
-
Verschachtelte Klassen - Übersicht
Von Klasse geerbte verschachtelte Klassen/Schnittstellen java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Feldübersicht
Von Klasse geerbte Felder java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
kCleanup()
Cleanup method called by run() just before termination.final boolean
Check if thread should be terminated.abstract void
kStart()
Main entry point for user thread.final void
kStop()
Set the thread termination flag and interrupt the thread.final void
kStop
(boolean argInterrupt) Set the thread termination flag and optionally send interrupt to the thread.final void
run()
Start thread by calling method kStart().final void
start()
Prohibit overwriting.toString()
Output object data.Von Klasse geerbte Methoden java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, startVirtualThread, stop, suspend, threadId, yield
-
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. -
start
public final void start()Prohibit overwriting. -
toString
Output object data.
-