diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java index fe10a09b..71cc5bed 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/executor/DynamicThreadPoolExecutor.java @@ -24,7 +24,9 @@ import cn.hippo4j.core.plugin.impl.TaskTimeoutNotifyAlarmPlugin; import cn.hippo4j.core.plugin.impl.ThreadPoolExecutorShutdownPlugin; import cn.hippo4j.core.plugin.manager.DefaultThreadPoolPluginManager; import cn.hippo4j.core.plugin.manager.DefaultThreadPoolPluginRegistrar; +import lombok.Getter; import lombok.NonNull; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.DisposableBean; import org.springframework.core.task.TaskDecorator; @@ -42,6 +44,13 @@ import java.util.concurrent.atomic.AtomicLong; @Slf4j public class DynamicThreadPoolExecutor extends ExtensibleThreadPoolExecutor implements DisposableBean { + /** + * wait for tasks to complete on shutdown + */ + @Getter + @Setter + public boolean waitForTasksToCompleteOnShutdown; + /** * Creates a new {@code DynamicThreadPoolExecutor} with the given initial parameters. * @@ -82,10 +91,10 @@ public class DynamicThreadPoolExecutor extends ExtensibleThreadPoolExecutor impl threadPoolId, new DefaultThreadPoolPluginManager(), corePoolSize, maximumPoolSize, keepAliveTime, unit, blockingQueue, threadFactory, rejectedExecutionHandler); - log.info("Initializing ExecutorService" + threadPoolId); - + log.info("Initializing ExecutorService {}", threadPoolId); + this.waitForTasksToCompleteOnShutdown = waitForTasksToCompleteOnShutdown; // init default plugins - new DefaultThreadPoolPluginRegistrar(executeTimeOut, awaitTerminationMillis, waitForTasksToCompleteOnShutdown) + new DefaultThreadPoolPluginRegistrar(executeTimeOut, awaitTerminationMillis) .doRegister(this); } @@ -116,19 +125,6 @@ public class DynamicThreadPoolExecutor extends ExtensibleThreadPoolExecutor impl .orElse(-1L); } - /** - * Is wait for tasks to complete on shutdown. - * - * @return true if instance wait for tasks to complete on shutdown, false other otherwise. - * @deprecated use {@link ThreadPoolExecutorShutdownPlugin} - */ - @Deprecated - public boolean isWaitForTasksToCompleteOnShutdown() { - return getPluginOfType(ThreadPoolExecutorShutdownPlugin.PLUGIN_NAME, ThreadPoolExecutorShutdownPlugin.class) - .map(ThreadPoolExecutorShutdownPlugin::isWaitForTasksToCompleteOnShutdown) - .orElse(false); - } - /** * Set support param. * @@ -138,10 +134,9 @@ public class DynamicThreadPoolExecutor extends ExtensibleThreadPoolExecutor impl */ @Deprecated public void setSupportParam(long awaitTerminationMillis, boolean waitForTasksToCompleteOnShutdown) { + setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown); getPluginOfType(ThreadPoolExecutorShutdownPlugin.PLUGIN_NAME, ThreadPoolExecutorShutdownPlugin.class) - .ifPresent(processor -> processor - .setAwaitTerminationMillis(awaitTerminationMillis) - .setWaitForTasksToCompleteOnShutdown(waitForTasksToCompleteOnShutdown)); + .ifPresent(processor -> processor.setAwaitTerminationMillis(awaitTerminationMillis)); } /** diff --git a/hippo4j-core/src/main/java/cn/hippo4j/core/plugin/impl/ThreadPoolExecutorShutdownPlugin.java b/hippo4j-core/src/main/java/cn/hippo4j/core/plugin/impl/ThreadPoolExecutorShutdownPlugin.java index e61fdfe1..114f2971 100644 --- a/hippo4j-core/src/main/java/cn/hippo4j/core/plugin/impl/ThreadPoolExecutorShutdownPlugin.java +++ b/hippo4j-core/src/main/java/cn/hippo4j/core/plugin/impl/ThreadPoolExecutorShutdownPlugin.java @@ -31,9 +31,8 @@ import java.util.List; import java.util.concurrent.*; /** - * After the thread pool calls {@link ThreadPoolExecutor#shutdown()} or {@link ThreadPoolExecutor#shutdownNow()}, - * if necessary, cancel the remaining tasks in the pool, - * and wait for the thread pool to terminate until + *
After the thread pool calls {@link ThreadPoolExecutor#shutdown()} or {@link ThreadPoolExecutor#shutdownNow()}.
+ * Cancel the remaining tasks in the pool, then wait for the thread pool to terminate until
* the blocked main thread has timed out or the thread pool has completely terminated.
*/
@Accessors(chain = true)
@@ -60,12 +59,6 @@ public class ThreadPoolExecutorShutdownPlugin implements ShutdownAwarePlugin {
@Setter
public long awaitTerminationMillis;
- /**
- * wait for tasks to complete on shutdown
- */
- @Setter
- public boolean waitForTasksToCompleteOnShutdown;
-
/**
* Callback before pool shutdown.
*
@@ -77,14 +70,13 @@ public class ThreadPoolExecutorShutdownPlugin implements ShutdownAwarePlugin {
ExtensibleThreadPoolExecutor dynamicThreadPoolExecutor = (ExtensibleThreadPoolExecutor) executor;
String threadPoolId = dynamicThreadPoolExecutor.getThreadPoolId();
if (log.isInfoEnabled()) {
- log.info("Before shutting down ExecutorService" + " '" + threadPoolId + "'");
+ log.info("Before shutting down ExecutorService {}", threadPoolId);
}
}
}
/**
- * Callback after pool shutdown.
- * if {@link #waitForTasksToCompleteOnShutdown} return {@code true},
+ * Callback after pool shutdown.
* cancel the remaining tasks,
* then wait for pool to terminate according {@link #awaitTerminationMillis} if necessary.
*
@@ -95,7 +87,7 @@ public class ThreadPoolExecutorShutdownPlugin implements ShutdownAwarePlugin {
public void afterShutdown(ThreadPoolExecutor executor, List