|
86 | 86 | * @author Eddú Meléndez
|
87 | 87 | * @author Quinten De Swaef
|
88 | 88 | * @author Venil Noronha
|
| 89 | + * @author Aurélien Leboulanger |
89 | 90 | */
|
90 | 91 | @ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
|
91 | 92 | public class ServerProperties
|
@@ -656,6 +657,19 @@ public static class Tomcat {
|
656 | 657 | */
|
657 | 658 | private Charset uriEncoding;
|
658 | 659 |
|
| 660 | + /** |
| 661 | + * Maximum amount of connections accept and process. |
| 662 | + * <p>Once the limit has been reached, |
| 663 | + * the operating system may still accept connections based on the @link{acceptCount} setting.</p> |
| 664 | + */ |
| 665 | + private int maxConnections = 0; |
| 666 | + |
| 667 | + /** |
| 668 | + * Maximum queue length for incoming connection requests when all possible request processing threads are in use. |
| 669 | + * Any requests received when the queue is full will be refused. |
| 670 | + */ |
| 671 | + private int acceptCount = 0; |
| 672 | + |
659 | 673 | public int getMaxThreads() {
|
660 | 674 | return this.maxThreads;
|
661 | 675 | }
|
@@ -748,6 +762,22 @@ public void setUriEncoding(Charset uriEncoding) {
|
748 | 762 | this.uriEncoding = uriEncoding;
|
749 | 763 | }
|
750 | 764 |
|
| 765 | + public int getMaxConnections() { |
| 766 | + return this.maxConnections; |
| 767 | + } |
| 768 | + |
| 769 | + public void setMaxConnections(int maxConnections) { |
| 770 | + this.maxConnections = maxConnections; |
| 771 | + } |
| 772 | + |
| 773 | + public int getAcceptCount() { |
| 774 | + return this.acceptCount; |
| 775 | + } |
| 776 | + |
| 777 | + public void setAcceptCount(int acceptCount) { |
| 778 | + this.acceptCount = acceptCount; |
| 779 | + } |
| 780 | + |
751 | 781 | void customizeTomcat(ServerProperties serverProperties,
|
752 | 782 | TomcatEmbeddedServletContainerFactory factory) {
|
753 | 783 | if (getBasedir() != null) {
|
@@ -782,6 +812,40 @@ void customizeTomcat(ServerProperties serverProperties,
|
782 | 812 | if (this.redirectContextRoot != null) {
|
783 | 813 | customizeRedirectContextRoot(factory, this.redirectContextRoot);
|
784 | 814 | }
|
| 815 | + if (this.maxConnections > 0) { |
| 816 | + customizeMaxConnections(factory); |
| 817 | + } |
| 818 | + if (this.acceptCount > 0) { |
| 819 | + customizeAcceptCount(factory); |
| 820 | + } |
| 821 | + } |
| 822 | + |
| 823 | + private void customizeAcceptCount(TomcatEmbeddedServletContainerFactory factory) { |
| 824 | + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { |
| 825 | + |
| 826 | + @Override |
| 827 | + public void customize(Connector connector) { |
| 828 | + ProtocolHandler handler = connector.getProtocolHandler(); |
| 829 | + if (handler instanceof AbstractProtocol) { |
| 830 | + AbstractProtocol protocol = (AbstractProtocol) handler; |
| 831 | + protocol.setBacklog(Tomcat.this.acceptCount); |
| 832 | + } |
| 833 | + } |
| 834 | + }); |
| 835 | + } |
| 836 | + |
| 837 | + private void customizeMaxConnections(TomcatEmbeddedServletContainerFactory factory) { |
| 838 | + factory.addConnectorCustomizers(new TomcatConnectorCustomizer() { |
| 839 | + |
| 840 | + @Override |
| 841 | + public void customize(Connector connector) { |
| 842 | + ProtocolHandler handler = connector.getProtocolHandler(); |
| 843 | + if (handler instanceof AbstractProtocol) { |
| 844 | + AbstractProtocol protocol = (AbstractProtocol) handler; |
| 845 | + protocol.setMaxConnections(Tomcat.this.maxConnections); |
| 846 | + } |
| 847 | + } |
| 848 | + }); |
785 | 849 | }
|
786 | 850 |
|
787 | 851 | private void customizeConnectionTimeout(
|
|
0 commit comments