Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for all close method to be completed before shutdown the ExecutorService #469

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -24,6 +24,7 @@
import org.dromara.dynamictp.core.notifier.manager.NoticeManager;
import org.dromara.dynamictp.core.support.DtpLifecycleSupport;
import org.dromara.dynamictp.core.system.SystemMetricManager;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.SmartLifecycle;

import java.util.concurrent.atomic.AtomicBoolean;
Expand All @@ -35,7 +36,7 @@
* @since 1.1.3
**/
@Slf4j
public class DtpLifecycle implements SmartLifecycle {
public class DtpLifecycle implements SmartLifecycle, DisposableBean {

private final AtomicBoolean running = new AtomicBoolean(false);

Expand All @@ -48,10 +49,6 @@ public void start() {

@Override
public void stop() {
if (this.running.compareAndSet(true, false)) {
shutdownInternal();
DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v));
}
}

@Override
Expand Down Expand Up @@ -87,7 +84,15 @@ public boolean isAutoStartup() {
*/
@Override
public int getPhase() {
return Integer.MAX_VALUE;
return Integer.MAX_VALUE -1;
}

@Override
public void destroy() throws Exception {
if (this.running.compareAndSet(true, false)) {
shutdownInternal();
DtpRegistry.getAllExecutors().forEach((k, v) -> DtpLifecycleSupport.destroy(v));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以设置awaitTerminationSeconds,延长等待时间

}
}

public void shutdownInternal() {
Expand Down