Merge pull request #339 from shining-stars-lk/develop

Fixed tomcat thread pool compatibility issues
pull/344/head
小马哥 3 years ago committed by GitHub
commit a2f11c234c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -127,7 +127,11 @@ public class ThreadPoolController {
} catch (Throwable ignored) { } catch (Throwable ignored) {
continue; continue;
} }
WebThreadPoolRespDTO result = BeanUtil.convert(poolBaseState.getData(), WebThreadPoolRespDTO.class); Object data = poolBaseState.getData();
if (data == null) {
continue;
}
WebThreadPoolRespDTO result = BeanUtil.convert(data, WebThreadPoolRespDTO.class);
result.setActive(each.getHolder().getActive()); result.setActive(each.getHolder().getActive());
result.setIdentify(each.getHolder().getIdentify()); result.setIdentify(each.getHolder().getIdentify());
result.setClientAddress(each.getHolder().getCallBackUrl()); result.setClientAddress(each.getHolder().getCallBackUrl());

@ -14,6 +14,11 @@
<groupId>cn.hippo4j</groupId> <groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-adapter-web</artifactId> <artifactId>hippo4j-adapter-web</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>
</dependencies> </dependencies>
<build> <build>

@ -23,11 +23,19 @@ import cn.hippo4j.core.executor.state.ThreadPoolRunStateHandler;
import cn.hippo4j.core.toolkit.inet.InetUtils; import cn.hippo4j.core.toolkit.inet.InetUtils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
import javax.servlet.Servlet;
import org.apache.catalina.startup.Tomcat;
import org.apache.coyote.UpgradeProtocol;
/** /**
* Web adapter auto configuration. * Web adapter auto configuration.
*/ */
@ -35,8 +43,6 @@ import org.springframework.core.env.ConfigurableEnvironment;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WebAdapterAutoConfiguration { public class WebAdapterAutoConfiguration {
private static final String TOMCAT_SERVLET_WEB_SERVER_FACTORY = "tomcatServletWebServerFactory";
private static final String JETTY_SERVLET_WEB_SERVER_FACTORY = "JettyServletWebServerFactory"; private static final String JETTY_SERVLET_WEB_SERVER_FACTORY = "JettyServletWebServerFactory";
private static final String UNDERTOW_SERVLET_WEB_SERVER_FACTORY = "undertowServletWebServerFactory"; private static final String UNDERTOW_SERVLET_WEB_SERVER_FACTORY = "undertowServletWebServerFactory";
@ -60,8 +66,14 @@ public class WebAdapterAutoConfiguration {
return new ThreadPoolRunStateHandler(hippo4JInetUtils, environment); return new ThreadPoolRunStateHandler(hippo4JInetUtils, environment);
} }
/**
* Refer to the Tomcat loading source code .
* This load is performed if the {@link Tomcat} class exists and
* the Web embedded server loads the {@link ServletWebServerFactory} top-level interface type at the same time
*/
@Bean @Bean
@ConditionalOnBean(name = TOMCAT_SERVLET_WEB_SERVER_FACTORY) @ConditionalOnClass({Servlet.class, Tomcat.class, UpgradeProtocol.class})
@ConditionalOnBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT)
public TomcatWebThreadPoolHandler tomcatWebThreadPoolHandler(WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) { public TomcatWebThreadPoolHandler tomcatWebThreadPoolHandler(WebThreadPoolRunStateHandler webThreadPoolRunStateHandler) {
return new TomcatWebThreadPoolHandler(webThreadPoolRunStateHandler); return new TomcatWebThreadPoolHandler(webThreadPoolRunStateHandler);
} }

Loading…
Cancel
Save