maxConnections or maxThreads on tomcat

Looking for advice - I've read the other two threads about this

in my server.xml file I have two places where maxThreads are defined in two places:

  1. <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="100" minSpareThreads="4"/>

AND

  1. <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="100" SSLEnabled="true" scheme="https" secure="true" connectionTimeout="600000" keystoreFile="/usr/local/tomcat/conf/keystore.p12" keystorePass="mypassword" clientAuth="false" sslProtocol="TLS" />

The error we are frequently running into with our server is : "Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available [size:100;busy:100;idle:0;lastwait:30000]" before a fatal shutdown of the system (the machine resets and starts up again - on an AWS ECS cluster)

When I increase the maxThreads value to 300 in the second instance listed here, we get the same error message - so I'm not sure if the connection size has increased at all. The system behaviour is different (machine doesnt restart) but then users cannot connect - it eventually needs manual restart.

How can I achieve more connections to the system or keep connectivity as high as possible?

In other posts about this topic some suggest decreasing maxThreads as well (assuming they complete quickly) could give better performance.

UPDATE:

in my application-properties file i had the following settings:

spring.datasource.url=jdbc:postgresql://db####
spring.datasource.username=#####
spring.datasource.password=######
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=60
spring.datasource.tomcat.test-on-borrow=true

spring.jpa.show-sql=false
#spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.hibernate.ddl-auto=validate
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

spring.jpa.hibernate.connection.provider_class=org.hibernate.c3p0.internal.C3P0ConnectionProvider
spring.jpa.properties.hibernate.c3p0.min_size=1
spring.jpa.properties.hibernate.c3p0.max_size=30
spring.jpa.properties.hibernate.c3p0.timeout=120
spring.jpa.properties.hibernate.c3p0.max_statements=20

Your application suffers from database connection pool exhaustion: since you have more working threads in Tomcat (100) than available connections in the connection pool (60), many threads need to wait for a connection to be available. You should have at least as many connections to the database as you have working threads. Try with:

spring.datasource.tomcat.max-active=200

Remark: Since your <Connector> does not have an executor attribute, the <Executor> you created is not used and can be deleted (unless another connector uses it).

Since there is no spring.jpa.hibernate.connection.provider_class property, the C3P0 connection pool you try to configure is never created: Hibernate will use the one configured through the spring.datasource.* properties. You can therefore remove the C3P0-related properties.