Package io.karatelabs.common
Class ThreadUtils
java.lang.Object
io.karatelabs.common.ThreadUtils
Shared concurrency helpers usable from karate-core and from any code that
embeds karate-core as a library.
Daemon thread factories are the cleanup contract every long-lived
subsystem in karate-core (HttpServer, WsClient, ProcessHandle, ...) relies
on: owners call close() / shutdownNow() explicitly, and if
those are skipped for any reason (test crash, programmer error, embedder
shutdown sequence) the daemon flag guarantees the JVM still terminates.
Two shapes are offered to cover both common cases:
daemonFactory(String)— numbered, for pools (cached / fixed thread pools, Netty event loop groups). Thread names areprefix + N(1-based).daemonFactory(String, boolean)— passnumbered=falsefor a fixed-name factory suitable forExecutors.newSingleThreadExecutor/newSingleThreadScheduledExecutor, where the thread name should match across restarts and grep cleanly.
-
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadFactorydaemonFactory(String prefix) Numbered daemon thread factory.static ThreadFactorydaemonFactory(String name, boolean numbered) Daemon thread factory.
-
Method Details
-
daemonFactory
Numbered daemon thread factory. Each spawned thread is namedprefix + N(N starts at 1). Right for pools where multiple threads can coexist. -
daemonFactory
Daemon thread factory.- Parameters:
name- thread name (or name prefix whennumberedis true)numbered- when true, threads are namedname + N(1-based); when false, every spawned thread is named exactlyname— suitable for single-thread executors where a stable name helps logs / thread dumps / grep
-