84. Task Executor¶
To support asynchronous task execution, SolarNode makes several thread-pool based services available to plugins:
- A
java.util.concurrent.Executor
service for standardRunnable
task execution - A Spring
TaskExecutor
service forRunnable
task execution - A Spring
AsyncTaskExecutor
service for bothRunnable
andCallable
task execution - A Spring
AsyncListenableTaskExecutor
service for bothRunnable
andCallable
task execution that supports theorg.springframework.util.concurrent.ListenableFuture
API
Need to schedule tasks?
See the Task Scheduler page for information on scheduling simple tasks, or the Job Scheduler page for information on scheduling managed jobs.
To make use of any of these services from a plugin using OSGi Blueprint you can declare a reference to them like this:
<reference id="taskExecutor" interface="java.util.concurrent.Executor"
filter="(function=node)"/>
<reference id="taskExecutor" interface="org.springframework.core.task.TaskExecutor"
filter="(function=node)"/>
<reference id="taskExecutor" interface="org.springframework.core.task.AsyncTaskExecutor"
filter="(function=node)"/>
<reference id="taskExecutor" interface="org.springframework.core.task.AsyncListenableTaskExecutor"
filter="(function=node)"/>
84.1 Thread pool configuration¶
This thread pool is configured as a fixed-size pool with the number of threads set to the number of CPU cores detected at runtime, plus one. For example on a Raspberry Pi 4 there are 4 CPU cores so the thread pool would be configured with 5 threads.