pull/117/head
weihu 3 years ago
parent d14a3ff8f8
commit 491cdacf74

@ -10,6 +10,8 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* Abstract web thread pool service.
@ -49,4 +51,17 @@ public abstract class AbstractWebThreadPoolService implements WebThreadPoolServi
return executor;
}
public void log(PoolParameterInfo poolParameterInfo, ThreadPoolExecutor threadPoolExecutor) {
int originalCoreSize = threadPoolExecutor.getCorePoolSize();
int originalMaximumPoolSize = threadPoolExecutor.getMaximumPoolSize();
long originalKeepAliveTime = threadPoolExecutor.getKeepAliveTime(TimeUnit.SECONDS);
log.info(
"🔥 Changed web thread pool. coreSize :: [{}], maxSize :: [{}], keepAliveTime :: [{}]",
String.format("%s => %s", originalCoreSize, poolParameterInfo.getCoreSize()),
String.format("%s => %s", originalMaximumPoolSize, poolParameterInfo.getMaxSize()),
String.format("%s => %s", originalKeepAliveTime, poolParameterInfo.getKeepAliveTime())
);
}
}

@ -29,20 +29,11 @@ public class JettyWebThreadPoolHandler extends AbstractWebThreadPoolService{
public void updateWebThreadPool(PoolParameterInfo poolParameterInfo) {
try {
ThreadPoolExecutor jettyExecutor = (ThreadPoolExecutor) executor;
int originalCoreSize = jettyExecutor.getCorePoolSize();
int originalMaximumPoolSize = jettyExecutor.getMaximumPoolSize();
long originalKeepAliveTime = jettyExecutor.getKeepAliveTime(TimeUnit.SECONDS);
jettyExecutor.setCorePoolSize(poolParameterInfo.getCoreSize());
jettyExecutor.setMaximumPoolSize(poolParameterInfo.getMaxSize());
jettyExecutor.setKeepAliveTime(poolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS);
log.info(
"🔥 Changed web thread pool. coreSize :: [{}], maxSize :: [{}], keepAliveTime :: [{}]",
String.format("%s => %s", originalCoreSize, poolParameterInfo.getCoreSize()),
String.format("%s => %s", originalMaximumPoolSize, poolParameterInfo.getMaxSize()),
String.format("%s => %s", originalKeepAliveTime, poolParameterInfo.getKeepAliveTime())
);
super.log(poolParameterInfo, jettyExecutor);
} catch (Exception ex) {
log.error("Failed to modify the jetty thread pool parameter.", ex);
}

@ -49,20 +49,12 @@ public class TomcatWebThreadPoolHandler extends AbstractWebThreadPoolService{
public void updateWebThreadPool(PoolParameterInfo poolParameterInfo) {
try {
ThreadPoolExecutor tomcatExecutor = (ThreadPoolExecutor) executor;
int originalCoreSize = tomcatExecutor.getCorePoolSize();
int originalMaximumPoolSize = tomcatExecutor.getMaximumPoolSize();
long originalKeepAliveTime = tomcatExecutor.getKeepAliveTime(TimeUnit.SECONDS);
tomcatExecutor.setCorePoolSize(poolParameterInfo.getCoreSize());
tomcatExecutor.setMaximumPoolSize(poolParameterInfo.getMaxSize());
tomcatExecutor.setKeepAliveTime(poolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS);
log.info(
"🔥 Changed web thread pool. coreSize :: [{}], maxSize :: [{}], keepAliveTime :: [{}]",
String.format("%s => %s", originalCoreSize, poolParameterInfo.getCoreSize()),
String.format("%s => %s", originalMaximumPoolSize, poolParameterInfo.getMaxSize()),
String.format("%s => %s", originalKeepAliveTime, poolParameterInfo.getKeepAliveTime())
);
super.log(poolParameterInfo, tomcatExecutor);
} catch (Exception ex) {
log.error("Failed to modify the Tomcat thread pool parameter.", ex);
}

@ -43,20 +43,11 @@ public class UndertowWebThreadPoolHandler extends AbstractWebThreadPoolService {
public void updateWebThreadPool(PoolParameterInfo poolParameterInfo) {
try {
ThreadPoolExecutor undertowExecutor = (ThreadPoolExecutor) executor;
int originalCoreSize = undertowExecutor.getCorePoolSize();
int originalMaximumPoolSize = undertowExecutor.getMaximumPoolSize();
long originalKeepAliveTime = undertowExecutor.getKeepAliveTime(TimeUnit.SECONDS);
undertowExecutor.setCorePoolSize(poolParameterInfo.getCoreSize());
undertowExecutor.setMaximumPoolSize(poolParameterInfo.getMaxSize());
undertowExecutor.setKeepAliveTime(poolParameterInfo.getKeepAliveTime(), TimeUnit.SECONDS);
super.log(poolParameterInfo, undertowExecutor);
log.info(
"🔥 Changed web thread pool. coreSize :: [{}], maxSize :: [{}], keepAliveTime :: [{}]",
String.format("%s => %s", originalCoreSize, poolParameterInfo.getCoreSize()),
String.format("%s => %s", originalMaximumPoolSize, poolParameterInfo.getMaxSize()),
String.format("%s => %s", originalKeepAliveTime, poolParameterInfo.getKeepAliveTime())
);
} catch (Exception ex) {
log.error("Failed to modify the undertow thread pool parameter.", ex);
}

Loading…
Cancel
Save