Allow Tomcat's minimum threads to be configured via the environment
Closes gh-5572
This commit is contained in:
committed by
Andy Wilkinson
parent
ca716561dc
commit
34eb3695e4
@@ -580,6 +580,11 @@ public class ServerProperties
|
||||
*/
|
||||
private int maxThreads = 0; // Number of threads in protocol handler
|
||||
|
||||
/**
|
||||
* Minimum amount of worker threads.
|
||||
*/
|
||||
private int minSpareThreads = 0; //Number of minimum spare threads in protocol handler
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of the HTTP message header.
|
||||
*/
|
||||
@@ -598,6 +603,14 @@ public class ServerProperties
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
public int getMinSpareThreads() {
|
||||
return minSpareThreads;
|
||||
}
|
||||
|
||||
public void setMinSpareThreads(int minSpareThreads) {
|
||||
this.minSpareThreads = minSpareThreads;
|
||||
}
|
||||
|
||||
public int getMaxHttpHeaderSize() {
|
||||
return this.maxHttpHeaderSize;
|
||||
}
|
||||
@@ -684,6 +697,9 @@ public class ServerProperties
|
||||
if (this.maxThreads > 0) {
|
||||
customizeMaxThreads(factory);
|
||||
}
|
||||
if (this.minSpareThreads > 0) {
|
||||
customizeMinThreads(factory);
|
||||
}
|
||||
if (this.maxHttpHeaderSize > 0) {
|
||||
customizeMaxHttpHeaderSize(factory);
|
||||
}
|
||||
@@ -747,6 +763,22 @@ public class ServerProperties
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void customizeMinThreads(TomcatEmbeddedServletContainerFactory factory) {
|
||||
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
|
||||
@Override
|
||||
public void customize(Connector connector) {
|
||||
|
||||
ProtocolHandler handler = connector.getProtocolHandler();
|
||||
if (handler instanceof AbstractProtocol) {
|
||||
AbstractProtocol protocol = (AbstractProtocol) handler;
|
||||
protocol.setMinSpareThreads(Tomcat.this.minSpareThreads);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void customizeMaxHttpHeaderSize(
|
||||
TomcatEmbeddedServletContainerFactory factory) {
|
||||
|
||||
@@ -258,6 +258,14 @@ public class ServerPropertiesTests {
|
||||
assertThat(this.properties.getTomcat().getMaxHttpHeaderSize()).isEqualTo(9999);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomizeTomcatMinSpareThreads() throws Exception {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("server.tomcat.min-spare-threads", "10");
|
||||
bindProperties(map);
|
||||
assertThat(this.properties.getTomcat().getMinSpareThreads()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizeTomcatDisplayName() throws Exception {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
Reference in New Issue
Block a user