Effective thread utilization using a thread-pool pattern
It is not always necessary to create a new thread for each task, as this can lead to improper resource usage. A thread-pool pattern may be a good solution to this challenge.
Motivation
A short-lived task does not need to create a new thread every time it runs, because each instantiation of a thread is related to the allocation of underlying resources. Wasting resources could result in an application throughput or performance penalty. A better option is described by the thread-pool pattern, which defines the required number of reusable threads to execute a critical section. Specific workers can transparently operate above the critical section code that needs to be executed.
Sample code
Let us imagine again a temperature measurement by sensors with different measurement dynamics (Example 6.16):
public static void main (String[] args) throws Exception{ System.out.println("Thread-Pool pattern...