fix: fix bugs for SyncTimeRecorder and ThreadPoolExecutorShutdownPlugin

pull/836/head
huangchengxing 3 years ago
parent 82b9261556
commit 313cedffc8

@ -134,7 +134,7 @@ public class SyncTimeRecorder {
* @return avg task time * @return avg task time
*/ */
public long getAvgTaskTimeMillis() { public long getAvgTaskTimeMillis() {
return getMinTaskTime() / getTaskCount(); return getTotalTaskTime() / getTaskCount();
} }
} }

@ -32,9 +32,9 @@ import java.util.Objects;
* @see TaskTimeoutNotifyAlarmPlugin * @see TaskTimeoutNotifyAlarmPlugin
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class TaskTimeRecordAwareProcessorPlugin extends SyncTimeRecorder implements ExecuteAwarePlugin { public class TaskTimeRecordPlugin extends SyncTimeRecorder implements ExecuteAwarePlugin {
public static final String PLUGIN_NAME = "task-time-record-aware-processor"; public static final String PLUGIN_NAME = "task-time-record-plugin";
/** /**
* Get id. * Get id.

@ -33,7 +33,7 @@ import java.util.Optional;
* @author huangchengxing * @author huangchengxing
*/ */
@AllArgsConstructor @AllArgsConstructor
public class TaskTimeoutNotifyAlarmPlugin extends TaskTimeRecordAwareProcessorPlugin { public class TaskTimeoutNotifyAlarmPlugin extends TaskTimeRecordPlugin {
public static final String PLUGIN_NAME = "task-timeout-notify-alarm-plugin"; public static final String PLUGIN_NAME = "task-timeout-notify-alarm-plugin";

@ -94,7 +94,7 @@ public class ThreadPoolExecutorShutdownPlugin implements ShutdownAwarePlugin {
*/ */
@Override @Override
public void afterShutdown(ThreadPoolExecutor executor, List<Runnable> remainingTasks) { public void afterShutdown(ThreadPoolExecutor executor, List<Runnable> remainingTasks) {
if (executor instanceof ExtensibleThreadPoolExecutor && CollectionUtil.isNotEmpty(remainingTasks)) { if (executor instanceof ExtensibleThreadPoolExecutor) {
ExtensibleThreadPoolExecutor pool = (ExtensibleThreadPoolExecutor) executor; ExtensibleThreadPoolExecutor pool = (ExtensibleThreadPoolExecutor) executor;
if (!waitForTasksToCompleteOnShutdown && CollectionUtil.isNotEmpty(remainingTasks)) { if (!waitForTasksToCompleteOnShutdown && CollectionUtil.isNotEmpty(remainingTasks)) {
remainingTasks.forEach(this::cancelRemainingTask); remainingTasks.forEach(this::cancelRemainingTask);

Loading…
Cancel
Save