|  | 
| 18 | 18 | 
 | 
| 19 | 19 | import java.time.Duration; | 
| 20 | 20 | import java.util.Arrays; | 
|  | 21 | +import java.util.function.Consumer; | 
| 21 | 22 | 
 | 
| 22 | 23 | import org.eclipse.jetty.server.AbstractConnector; | 
| 23 | 24 | import org.eclipse.jetty.server.ConnectionFactory; | 
| @@ -82,11 +83,11 @@ public void customize(ConfigurableJettyWebServerFactory factory) { | 
| 82 | 83 | 		propertyMapper.from(jettyProperties::getMaxHttpPostSize).asInt(DataSize::toBytes).when(this::isPositive) | 
| 83 | 84 | 				.to((maxHttpPostSize) -> customizeMaxHttpPostSize(factory, maxHttpPostSize)); | 
| 84 | 85 | 		propertyMapper.from(jettyProperties::getMaxThreads).when(this::isPositive) | 
| 85 |  | -				.to((maxThreads) -> customizeMaxThreads(factory, maxThreads)); | 
|  | 86 | +				.to((maxThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMaxThreads(maxThreads))); | 
| 86 | 87 | 		propertyMapper.from(jettyProperties::getMinThreads).when(this::isPositive) | 
| 87 |  | -				.to((minThreads) -> customizeMinThreads(factory, minThreads)); | 
| 88 |  | -		propertyMapper.from(jettyProperties::getIdleTimeout).when(this::isPositive) | 
| 89 |  | -				.to((idleTimeout) -> customizeIdleTimeout(factory, idleTimeout)); | 
|  | 88 | +				.to((minThreads) -> customizeThreadPool(factory, (threadPool) -> threadPool.setMinThreads(minThreads))); | 
|  | 89 | +		propertyMapper.from(jettyProperties::getIdleTimeout).when(this::isPositive).to( | 
|  | 90 | +				(idleTimeout) -> customizeThreadPool(factory, (threadPool) -> threadPool.setIdleTimeout(idleTimeout))); | 
| 90 | 91 | 		propertyMapper.from(properties::getConnectionTimeout).whenNonNull() | 
| 91 | 92 | 				.to((connectionTimeout) -> customizeConnectionTimeout(factory, connectionTimeout)); | 
| 92 | 93 | 		propertyMapper.from(jettyProperties::getAccesslog).when(ServerProperties.Jetty.Accesslog::isEnabled) | 
| @@ -140,29 +141,11 @@ else if (handler instanceof HandlerCollection) { | 
| 140 | 141 | 		}); | 
| 141 | 142 | 	} | 
| 142 | 143 | 
 | 
| 143 |  | -	private void customizeMaxThreads(ConfigurableJettyWebServerFactory factory, int maxThreads) { | 
|  | 144 | +	private void customizeThreadPool(ConfigurableJettyWebServerFactory factory, Consumer<QueuedThreadPool> customizer) { | 
| 144 | 145 | 		factory.addServerCustomizers((connector) -> { | 
| 145 | 146 | 			ThreadPool threadPool = connector.getThreadPool(); | 
| 146 | 147 | 			if (threadPool instanceof QueuedThreadPool) { | 
| 147 |  | -				((QueuedThreadPool) threadPool).setMaxThreads(maxThreads); | 
| 148 |  | -			} | 
| 149 |  | -		}); | 
| 150 |  | -	} | 
| 151 |  | - | 
| 152 |  | -	private void customizeMinThreads(ConfigurableJettyWebServerFactory factory, int minThreads) { | 
| 153 |  | -		factory.addServerCustomizers((connector) -> { | 
| 154 |  | -			ThreadPool threadPool = connector.getThreadPool(); | 
| 155 |  | -			if (threadPool instanceof QueuedThreadPool) { | 
| 156 |  | -				((QueuedThreadPool) threadPool).setMinThreads(minThreads); | 
| 157 |  | -			} | 
| 158 |  | -		}); | 
| 159 |  | -	} | 
| 160 |  | - | 
| 161 |  | -	private void customizeIdleTimeout(ConfigurableJettyWebServerFactory factory, int idleTimeout) { | 
| 162 |  | -		factory.addServerCustomizers((connector) -> { | 
| 163 |  | -			ThreadPool threadPool = connector.getThreadPool(); | 
| 164 |  | -			if (threadPool instanceof QueuedThreadPool) { | 
| 165 |  | -				((QueuedThreadPool) threadPool).setIdleTimeout(idleTimeout); | 
|  | 148 | +				customizer.accept((QueuedThreadPool) threadPool); | 
| 166 | 149 | 			} | 
| 167 | 150 | 		}); | 
| 168 | 151 | 	} | 
|  | 
0 commit comments