
βοΈJava Thread
Make difficult Java thread creation and cleanup a thing of the past.
Last updated
public class TestThread extends KThread {
private String gStartArgument = null;
public TestThread(String argString) {
gStartArgument = argString;
}
public void kStart() {
KLog.info("Thread has started with argument " + gStartArgument);
while (!kMustTerminate()) {
KLog.info("Thread still running ...");
K.waitSeconds(1);
}
KLog.info("Thread has terminated");
}
public synchronized void kCleanup() {
KLog.info("Thread cleanup called");
}
}2024-09-05T14:42:52.629 I main[1]:Test:main:9 Start
2024-09-05T14:42:52.629 I main[1]:Test:thread:20 Thread created and started
2024-09-05T14:42:52.630 I T-0[15]:TestThread:kStart:15 Thread has started with argument Hello World
2024-09-05T14:42:52.630 I T-0[15]:TestThread:kStart:18 Thread still running ...
2024-09-05T14:42:53.636 I T-0[15]:TestThread:kStart:18 Thread still running ...
2024-09-05T14:42:54.641 I T-0[15]:TestThread:kStart:18 Thread still running ...
2024-09-05T14:42:55.646 I T-0[15]:TestThread:kStart:18 Thread still running ...
2024-09-05T14:42:56.654 I T-0[15]:TestThread:kStart:18 Thread still running ...
2024-09-05T14:42:57.637 E T-0[15]:ch.k43.util.K:waitThread:1484 ===> java.lang.InterruptedException: sleep interrupted
2024-09-05T14:42:57.638 I T-0[15]:TestThread:kStart:22 Thread has terminated
2024-09-05T14:42:57.639 I T-0[15]:TestThread:kCleanup:27 Thread cleanup called