Class AnahataExecutors
java.lang.Object
uno.anahata.ai.AnahataExecutors
A utility class for creating and managing named
ExecutorService instances
for various asynchronous tasks within the Anahata AI framework.
This class ensures that all threads are properly named, configured as daemons, and managed consistently to prevent resource leaks and ensure clean application shutdown.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ExecutorServiceA shared, fixed-size thread pool optimized for CPU-intensive, parallelizable tasks. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExecutorServicenewCachedThreadPoolExecutor(String threadPrefix) Creates a new cached thread pool.static ExecutorServicenewFixedThreadPoolExecutor(int size, String threadPrefix) Creates a new thread pool with a fixed number of threads.
-
Field Details
-
SHARED_CPU_EXECUTOR
A shared, fixed-size thread pool optimized for CPU-intensive, parallelizable tasks. The size is set to the number of available processor cores to maximize throughput without performance degradation from excessive context switching.
-
-
Constructor Details
-
AnahataExecutors
public AnahataExecutors()
-
-
Method Details
-
newCachedThreadPoolExecutor
Creates a new cached thread pool. Threads in this pool are created as needed and will be reused if available. This type of pool is suitable for executing many short-lived asynchronous tasks. Threads are created as daemon threads to prevent them from blocking application shutdown.- Parameters:
threadPrefix- The prefix for the thread name, used for identification in logs and debuggers.- Returns:
- A new cached thread pool ExecutorService.
-
newFixedThreadPoolExecutor
Creates a new thread pool with a fixed number of threads. This is ideal for CPU-intensive tasks where the number of concurrent operations should be limited to the number of available cores to avoid performance degradation from excessive context switching. Threads are created as daemon threads.- Parameters:
size- The fixed number of threads in the pool.threadPrefix- The prefix for the thread name, used for identification.- Returns:
- A new fixed-size thread pool ExecutorService.
-
