简体   繁体   中英

What is the advantage of using WaterMarkExecutor over ThreadPoolExecutor?

Apache introduced a new Thread Pool called WaterMarkExecutor that extends ThreadPoolExecutor . But i could not understand the motive of WaterMarkExecutor. Why it is needed? and what advantage does it have over ThreadPoolExecutor?

The documentation seems to suggest the water mark is on the queue size. If the queue gets to a certain size, more threads will be added until the maximum number of threads. This is different from the normal executor that starts adding threads as soon as all the other threads are used.

This would be useful if you only want to create more threads, and possibly add load to your system, after a certain number of tasks has queued up. It is a balancing act between system load and queue draining speed.

In this executor after all the core pool threads are used queuing happens until the water mark. If the more tasks are submitted after the queue is filled up to the water mark the number of threads increases to max. If the number of tasks continue to increase the Queue begins to fill up. If the queue is a bounded queue and the queue is completely filled a RejectedExecutionHandler is executed if one specified. Otherwise the task is rejected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM