I'm using BasicDataSource (org.apache.commons.dbcp2.BasicDataSource) with a local MySQL database. My application is a Java web service running under Tomcat 8 on an AWS Linux server.
No matter how I configure the connection pool, 8 is the maximum number of connections I can get at once. When I try to retrieve the 9th connection, not only does it fail, but it basically locks up the entire Tomcat instance. This happens even if I configure a short maximum wait time.
I've isolated the problem by writing a test function that tries to allocate and close 10 connections. I'm running the test on an isolated dev server that is not processing any other requests. I know that the same problem is happening on my production server because it fails intermittently and when it does I have noticed that 8 database connections are allocated and a thread dump shows many other threads waiting for a connection.
The MySQL database is configured as default, which should permit up to 150 connections. I've checked this by signing in to the database and looking at the variables.
What can I do to diagnose this problem?