使用 WaterMarkExecutor 比使用 ThreadPoolExecutor 有什么优势?
What is the advantage of using WaterMarkExecutor over ThreadPoolExecutor?
Apache 引入了一个名为 WaterMarkExecutor that extends ThreadPoolExecutor 的新线程池。但我无法理解 WaterMarkExecutor 的动机。为什么需要它?它比 ThreadPoolExecutor 有什么优势?
documentation 似乎表明水印在队列大小上。如果队列达到一定大小,将添加更多线程,直到达到最大线程数。这与使用所有其他线程后立即开始添加线程的普通执行程序不同。
如果您只想创建更多线程,并可能在一定数量的任务排队后增加系统负载,这将很有用。这是系统负载和队列排空速度之间的平衡行为。
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.
Apache 引入了一个名为 WaterMarkExecutor that extends ThreadPoolExecutor 的新线程池。但我无法理解 WaterMarkExecutor 的动机。为什么需要它?它比 ThreadPoolExecutor 有什么优势?
documentation 似乎表明水印在队列大小上。如果队列达到一定大小,将添加更多线程,直到达到最大线程数。这与使用所有其他线程后立即开始添加线程的普通执行程序不同。
如果您只想创建更多线程,并可能在一定数量的任务排队后增加系统负载,这将很有用。这是系统负载和队列排空速度之间的平衡行为。
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.