mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-05 00:56:58 +08:00
Upgrade to Tomcat 10.1.19
Closes gh-39673
This commit is contained in:
parent
d86fa721b5
commit
71e3a92f3c
@ -14,6 +14,6 @@ kotlinVersion=1.9.22
|
||||
mavenVersion=3.9.4
|
||||
nativeBuildToolsVersion=0.9.28
|
||||
springFrameworkVersion=6.1.4
|
||||
tomcatVersion=10.1.18
|
||||
tomcatVersion=10.1.19
|
||||
|
||||
kotlin.stdlib.default.dependency=false
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2023 the original author or authors.
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -19,6 +19,7 @@ package org.springframework.boot.web.embedded.tomcat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import org.apache.catalina.Container;
|
||||
import org.apache.catalina.Service;
|
||||
@ -51,32 +52,44 @@ final class GracefulShutdown {
|
||||
|
||||
void shutDownGracefully(GracefulShutdownCallback callback) {
|
||||
logger.info("Commencing graceful shutdown. Waiting for active requests to complete");
|
||||
new Thread(() -> doShutdown(callback), "tomcat-shutdown").start();
|
||||
}
|
||||
|
||||
private void doShutdown(GracefulShutdownCallback callback) {
|
||||
List<Connector> connectors = getConnectors();
|
||||
connectors.forEach(this::close);
|
||||
CountDownLatch shutdownUnderway = new CountDownLatch(1);
|
||||
new Thread(() -> doShutdown(callback, shutdownUnderway), "tomcat-shutdown").start();
|
||||
try {
|
||||
for (Container host : this.tomcat.getEngine().findChildren()) {
|
||||
for (Container context : host.findChildren()) {
|
||||
while (!this.aborted && isActive(context)) {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
if (this.aborted) {
|
||||
logger.info("Graceful shutdown aborted with one or more requests still active");
|
||||
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shutdownUnderway.await();
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
logger.info("Graceful shutdown complete");
|
||||
callback.shutdownComplete(GracefulShutdownResult.IDLE);
|
||||
}
|
||||
|
||||
private void doShutdown(GracefulShutdownCallback callback, CountDownLatch shutdownUnderway) {
|
||||
try {
|
||||
List<Connector> connectors = getConnectors();
|
||||
connectors.forEach(this::close);
|
||||
shutdownUnderway.countDown();
|
||||
try {
|
||||
for (Container host : this.tomcat.getEngine().findChildren()) {
|
||||
for (Container context : host.findChildren()) {
|
||||
while (!this.aborted && isActive(context)) {
|
||||
Thread.sleep(50);
|
||||
}
|
||||
if (this.aborted) {
|
||||
logger.info("Graceful shutdown aborted with one or more requests still active");
|
||||
callback.shutdownComplete(GracefulShutdownResult.REQUESTS_ACTIVE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
logger.info("Graceful shutdown complete");
|
||||
callback.shutdownComplete(GracefulShutdownResult.IDLE);
|
||||
}
|
||||
finally {
|
||||
shutdownUnderway.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
private List<Connector> getConnectors() {
|
||||
|
Loading…
Reference in New Issue
Block a user