Polish contribution
This commit: - fixes Checkstyle violations - improves Javadoc - adds missing @since tags - renames getCurrentQueueSize() to getQueueSize() - avoids NullPointerExceptions in getQueueSize() - introduces tests for queue size and queue capacity Closes gh-28583
This commit is contained in:
@@ -72,6 +72,8 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
* {@link org.springframework.scheduling.concurrent.ConcurrentTaskExecutor} adapter.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rémy Guihard
|
||||
* @author Sam Brannen
|
||||
* @since 2.0
|
||||
* @see org.springframework.core.task.TaskExecutor
|
||||
* @see java.util.concurrent.ThreadPoolExecutor
|
||||
@@ -155,7 +157,7 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
|
||||
/**
|
||||
* Set the ThreadPoolExecutor's keep-alive seconds.
|
||||
* Default is 60.
|
||||
* <p>Default is 60.
|
||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||
*/
|
||||
public void setKeepAliveSeconds(int keepAliveSeconds) {
|
||||
@@ -178,7 +180,7 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
|
||||
/**
|
||||
* Set the capacity for the ThreadPoolExecutor's BlockingQueue.
|
||||
* Default is {@code Integer.MAX_VALUE}.
|
||||
* <p>Default is {@code Integer.MAX_VALUE}.
|
||||
* <p>Any positive value will lead to a LinkedBlockingQueue instance;
|
||||
* any other value will lead to a SynchronousQueue instance.
|
||||
* @see java.util.concurrent.LinkedBlockingQueue
|
||||
@@ -188,6 +190,15 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
this.queueCapacity = queueCapacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the capacity for the ThreadPoolExecutor's BlockingQueue.
|
||||
* @since 5.3.21
|
||||
* @see #setQueueCapacity(int)
|
||||
*/
|
||||
public int getQueueCapacity() {
|
||||
return this.queueCapacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to allow core threads to time out. This enables dynamic
|
||||
* growing and shrinking even in combination with a non-zero queue (since
|
||||
@@ -315,19 +326,18 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
}
|
||||
return this.threadPoolExecutor.getPoolSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current number of threads waiting in the queue
|
||||
*/
|
||||
public int getCurrentQueueSize() {
|
||||
return this.getThreadPoolExecutor().getQueue().size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the maximum capacity of the queue
|
||||
*/
|
||||
public int getQueueCapacity() {
|
||||
return this.queueCapacity;
|
||||
* Return the current queue size.
|
||||
* @since 5.3.21
|
||||
* @see java.util.concurrent.ThreadPoolExecutor#getQueue()
|
||||
*/
|
||||
public int getQueueSize() {
|
||||
if (this.threadPoolExecutor == null) {
|
||||
// Not initialized yet: assume no queued tasks.
|
||||
return 0;
|
||||
}
|
||||
return this.threadPoolExecutor.getQueue().size();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user