|
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
|
@@ -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) {
|
@@ -806,6 +836,40 @@ void customizeTomcat(ServerProperties serverProperties,
|
806 | 836 | if (this.redirectContextRoot != null) {
|
807 | 837 | customizeRedirectContextRoot(factory, this.redirectContextRoot);
|
808 | 838 | }
|
| 839 | + if (this.maxConnections > 0) { |
| 840 | + customizeMaxConnections(factory); |
| 841 | + } |
| 842 | + if (this.acceptCount != 100) { |
| 843 | + customizeAcceptCount(factory); |
| 844 | + } |
| 845 | + } |
| 846 | + |
| 847 | + private void customizeAcceptCount(TomcatEmbeddedServletContainerFactory factory) { |
| 848 | + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { |
| 849 | + |
| 850 | + @Override |
| 851 | + public void customize(Connector connector) { |
| 852 | + ProtocolHandler handler = connector.getProtocolHandler(); |
| 853 | + if (handler instanceof AbstractProtocol) { |
| 854 | + AbstractProtocol protocol = (AbstractProtocol) handler; |
| 855 | + protocol.setBacklog(Tomcat.this.acceptCount); |
| 856 | + } |
| 857 | + } |
| 858 | + }); |
| 859 | + } |
| 860 | + |
| 861 | + private void customizeMaxConnections(TomcatEmbeddedServletContainerFactory factory) { |
| 862 | + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { |
| 863 | + |
| 864 | + @Override |
| 865 | + public void customize(Connector connector) { |
| 866 | + ProtocolHandler handler = connector.getProtocolHandler(); |
| 867 | + if (handler instanceof AbstractProtocol) { |
| 868 | + AbstractProtocol protocol = (AbstractProtocol) handler; |
| 869 | + protocol.setMaxConnections(Tomcat.this.maxConnections); |
| 870 | + } |
| 871 | + } |
| 872 | + }); |
809 | 873 | }
|
810 | 874 |
|
811 | 875 | private void customizeConnectionTimeout(
|
|
0 commit comments