The ThreadPool component is a pool of threads used to process jobs submitted to the pool. The jobs are queued for handling.
When the configurable number of jobs in the queue is reached, further jobs can be blocked or rejected; if the job is rejected, an error is returned.
If job priority is configured, the processing thread runs at the set priority. This implies that the POSIX FIFO policy is applied and means that the job queue must queue the jobs by priority.
If thread affinity is configured, all threads in a pool run on the specified CPU.
The thread pool can be stopped and started multiple times.
You can configure the following:
- The number of initial threads in a pool
- The maximum number of jobs in the queue
- Thread affinity
- Whether to wait until all scheduled jobs complete
The following table describes the configuration variables that can be used with the ThreadPool component:
|Name of the Logger component to use
|The name of an existing Logger component
|The number of pool threads
IoTech recommends that you calculate the size of your thread pool to make the best use of time and resources
Default value is 2
|The maximum number of queued jobs
|Default value is 0 (no limit)
|The priority of the pool threads
The range is system-dependent
For example on Linux it is usually between 1 and 100 with 1 being the lowest priority and 100 being the highest priority
|The processor affinity of pool threads
|The number of the CPU to use in the range 0 to n
|The maximum interval in milliseconds that the pool waits for threads to complete when the pool is free
|Default value is 200
All the configuration variables are optional.
The following example configures a ThreadPool component with a maximum queue of ten jobs, processed on CPU 11 with a priority of 99, and which waits for 2000ms for the threads to complete when the pool is free: