87
87
* @author Eddú Meléndez
88
88
* @author Quinten De Swaef
89
89
* @author Venil Noronha
90
+ * @author Aurélien Leboulanger
90
91
*/
91
92
@ ConfigurationProperties (prefix = "server" , ignoreUnknownFields = true )
92
93
public class ServerProperties
@@ -643,7 +644,7 @@ public static class Tomcat {
643
644
644
645
/**
645
646
* Maximum size in bytes of the HTTP message header.
646
- */
647
+ */
647
648
private int maxHttpHeaderSize = 0 ; // bytes
648
649
649
650
/**
@@ -657,6 +658,19 @@ public static class Tomcat {
657
658
*/
658
659
private Charset uriEncoding ;
659
660
661
+ /**
662
+ * Maximum amount of connections accept and process.
663
+ * <p>Once the limit has been reached,
664
+ * the operating system may still accept connections based on the @link{acceptCount} setting.</p>
665
+ */
666
+ private int maxConnections = 0 ;
667
+
668
+ /**
669
+ * Maximum queue length for incoming connection requests when all possible request processing threads are in use.
670
+ * Any requests received when the queue is full will be refused. The default value is 100.
671
+ */
672
+ private int acceptCount = 100 ;
673
+
660
674
public int getMaxThreads () {
661
675
return this .maxThreads ;
662
676
}
@@ -772,6 +786,22 @@ public void setUriEncoding(Charset uriEncoding) {
772
786
this .uriEncoding = uriEncoding ;
773
787
}
774
788
789
+ public int getMaxConnections () {
790
+ return this .maxConnections ;
791
+ }
792
+
793
+ public void setMaxConnections (int maxConnections ) {
794
+ this .maxConnections = maxConnections ;
795
+ }
796
+
797
+ public int getAcceptCount () {
798
+ return this .acceptCount ;
799
+ }
800
+
801
+ public void setAcceptCount (int acceptCount ) {
802
+ this .acceptCount = acceptCount ;
803
+ }
804
+
775
805
void customizeTomcat (ServerProperties serverProperties ,
776
806
TomcatEmbeddedServletContainerFactory factory ) {
777
807
if (getBasedir () != null ) {
@@ -799,24 +829,40 @@ void customizeTomcat(ServerProperties serverProperties,
799
829
if (getUriEncoding () != null ) {
800
830
factory .setUriEncoding (getUriEncoding ());
801
831
}
802
- if (serverProperties .getConnectionTimeout () != null ) {
803
- customizeConnectionTimeout (factory ,
804
- serverProperties .getConnectionTimeout ());
832
+ if (this .maxConnections > 0 ) {
833
+ customizeMaxConnections (factory );
805
834
}
806
- if (this .redirectContextRoot != null ) {
807
- customizeRedirectContextRoot (factory , this . redirectContextRoot );
835
+ if (this .acceptCount != 100 ) {
836
+ customizeAcceptCount (factory );
808
837
}
809
838
}
810
839
811
- private void customizeConnectionTimeout (
812
- TomcatEmbeddedServletContainerFactory factory , int connectionTimeout ) {
813
- for (Connector connector : factory .getAdditionalTomcatConnectors ()) {
814
- if (connector .getProtocolHandler () instanceof AbstractProtocol ) {
815
- AbstractProtocol <?> handler = (AbstractProtocol <?>) connector
816
- .getProtocolHandler ();
817
- handler .setConnectionTimeout (connectionTimeout );
840
+ private void customizeAcceptCount (TomcatEmbeddedServletContainerFactory factory ) {
841
+ factory .addConnectorCustomizers (new TomcatConnectorCustomizer () {
842
+
843
+ @ Override
844
+ public void customize (Connector connector ) {
845
+ ProtocolHandler handler = connector .getProtocolHandler ();
846
+ if (handler instanceof AbstractProtocol ) {
847
+ AbstractProtocol protocol = (AbstractProtocol ) handler ;
848
+ protocol .setBacklog (Tomcat .this .acceptCount );
849
+ }
818
850
}
819
- }
851
+ });
852
+ }
853
+
854
+ private void customizeMaxConnections (TomcatEmbeddedServletContainerFactory factory ) {
855
+ factory .addConnectorCustomizers (new TomcatConnectorCustomizer () {
856
+
857
+ @ Override
858
+ public void customize (Connector connector ) {
859
+ ProtocolHandler handler = connector .getProtocolHandler ();
860
+ if (handler instanceof AbstractProtocol ) {
861
+ AbstractProtocol protocol = (AbstractProtocol ) handler ;
862
+ protocol .setMaxConnections (Tomcat .this .maxConnections );
863
+ }
864
+ }
865
+ });
820
866
}
821
867
822
868
private void customizeBackgroundProcessorDelay (
0 commit comments