Executors
The ColdBox AsyncManager will allow you to register and manage different types of executors that can execute your very own tasks! Each executor acts as a singleton and can be configured uniquely. (See: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html)
You can also create executors on the fly so your async futures can use them as well for ONLY that execution stage.
Nice video explaining the Java Executor Service: https://www.youtube.com/watch?v=6Oo-9Can3H8&t=2s
Executor Types
The types that we currently support are:
fixed: By default it will build one with 20 threads on it. Great for multiple task execution and worker processing.

single: A great way to control that submitted tasks will execute in the order of submission much like a FIFO queue (First In First Out).

cached: An unbounded pool where the number of threads will grow according to the tasks it needs to service. The threads are killed by a default 60 second timeout if not used and the pool shrinks back to 0.

scheduled: A pool to use for scheduled tasks that can run one time or periodically. The default scheduled task queue has 20 threads for processing.

Please note that each executor is unique in its way of operation, so make sure you read about each type in the JavaDocs or watch this amazing video: https://www.youtube.com/watch?v=sIkG0X4fqs4
Executor Methods
Here are the methods you can use for registering and managing singleton executors in your application:
newExecutor(): Create and register an executor according to passed arguments. If the executor exists, just return it.newScheduledExecutor(): Create a scheduled executor according to passed arguments. Shortcut tonewExecutor( type: "scheduled" )newSingleExecutor(): Create a single thread executor. Shortcut tonewExecutor( type: "single", threads: 1 )newCachedExecutor(): Create a cached thread executor. Shortcut tonewExecutor( type: "cached" )getExecutor(): Get a registered executor registerd in this async managergetExecutorNames(): Get the array of registered executors in the systemhasExecutor(): Verify if an executor existsdeleteExecutor(): Delete an executor from the registry, if the executor has not shutdown, it will shutdown the executor for you using the shutdownNow() eventshutdownExecutor(): Shutdown an executor or force it to shutdown, you can also do this from the Executor themselves. If an un-registered executor name is passed, it will ignore itshutdownAllExecutors(): Shutdown all registered executors in the systemgetExecutorStatusMap(): Returns a structure of status maps for every registered executor in the manager. This is composed of tons of stats about the executor.
And here are the full signatures:
Single Use Executors
If you just want to use executors for different completion stages and then discard them, you can easily do so by using the $executors public component in the AsyncManager. This object can be found at: coldbox.system.async.util.Executors:
The available creation methods are:
This way you can use them and discard them upon further processing.
ColdBox Task Scheduler
Every ColdBox application will register a task scheduler called coldbox-tasks which ColdBox internal services can leverage it for tasks and schedules. It is configured with 20 threads and using the scheduled type. You can leverage if you wanted to for your own tasks as well.
ColdBox Application Executor Registration
We have also added a new configuration struct called executors which you can use to register global executors or per-module executors.
Each executor registration is done as a struct with the name of the executor and at most two settings:
type: The executor type you want to registerthreads: The number of threads to assign to the executor
ModuleConfig.cfc
You can also do the same at a per-module level in your module's ModuleConfig.cfc.
ColdBox will register your executors upon startup and un-register and shut them down when the module is unloaded.
WireBox Injection DSL
We have extended WireBox so you can inject registered executors using the following DSL: executors:{name}
Last updated
Was this helpful?