Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ReservedThreadExecutor(Executor executor, int capacity)
*/
public ReservedThreadExecutor(Executor executor, int capacity, int minSize)
{
this(executor, capacity, minSize, -1);
this(executor, capacity, minSize, 0);
}

/**
Expand All @@ -83,7 +83,7 @@ public ReservedThreadExecutor(Executor executor, int capacity, int minSize)
* is calculated based on a heuristic from the number of available processors and
* thread pool type.
* @param minSize The minimum number of reserve Threads that the algorithm tries to maintain, or -1 for a heuristic value.
* @param maxPending The maximum number of reserved Threads to start, or -1 for no limit.
* @param maxPending The maximum number of reserved Threads to start, 0 (default) for thread pool capacity or -1 for no limit.
*/
public ReservedThreadExecutor(Executor executor, int capacity, int minSize, int maxPending)
{
Expand All @@ -92,9 +92,14 @@ public ReservedThreadExecutor(Executor executor, int capacity, int minSize, int
_minSize = minSize < 0 ? Math.min(1, _threads.capacity()) : minSize;
if (_minSize > _threads.capacity())
throw new IllegalArgumentException("minSize larger than capacity");
_maxPending = maxPending;
if (_maxPending == 0)
throw new IllegalArgumentException("maxPending cannot be 0");

if (maxPending < 0)
_maxPending = -1;
else if (maxPending == 0)
_maxPending = _threads.capacity();
else
_maxPending = maxPending;

if (LOG.isDebugEnabled())
LOG.debug("{}", this);
installBean(_executor);
Expand Down Expand Up @@ -227,7 +232,7 @@ public boolean tryExecute(Runnable task)

private void startReservedThread()
{
if (_maxPending > 0 && _pending.incrementAndGet() >= _maxPending)
if (_maxPending > 0 && _pending.incrementAndGet() > _maxPending)
{
_pending.decrementAndGet();
return;
Expand Down