Java supports threads and offers a broad set of thread-related functionality, from creating individual threads to managing thread pools with configurable characteristics.
Many times, developers don’t need dedicated threads, but instead need a background thread to decouple or perform work, or a thread to act as a timer. In most of these cases, a thread only executes a small amount of work before being released. In light of this, KOS provides several thread-related resources that allow developers to avoid the complexity of managing threads.
Worker thread pool: KOS provides an existing thread pool of worker threads which are accessible through the Scheduler interface. This thread pool is suitable for short running operations and will automatically handle top-level exception handling. This is an easy way to avoid the need for a dedicated thread or thread pool for simple decoupled work.
Scheduled thread pool: KOS provides an existing scheduled thread pool which are used to perform operations in a thread at a certain time or after a specified delay. This thread pool is used extensively by the KOS timer infrastructure.
Starting a thread: The Scheduler interface provides a convenience method to start a single thread in the event that there is a need for a long-running or dedicated thread.
In many cases KOS applications rarely require dedicated threads. It is common that listener events and timers cover most use cases. By providing convenience methods to access existing thread pools, KOS attempts to offload the overhead and bookkeeping of thread management from application developers.