92. Task Executor¶
To support asynchronous task execution, SolarNode makes several thread-pool based services available to plugins:
- A
java.util.concurrent.Executorservice for standardRunnabletask execution - A Spring
TaskExecutorservice forRunnabletask execution - A Spring
AsyncTaskExecutorservice for bothRunnableandCallabletask execution - A Spring
AsyncListenableTaskExecutorservice for bothRunnableandCallabletask execution that supports theorg.springframework.util.concurrent.ListenableFutureAPI
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)"/>
92.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.