It's not a good idea to use PGPoolingDataSource , as the JDBC documentation explains .
The main problem is that the call to getConnection () will be blocked until the connection is closed when the connection limit is reached.
You set 30 as the maximum number of concurrent connections, so if the 31st is to be opened, it will block the thread making the call.
Possible solutions:
- Increase maxConnections if you are sure of the actual size of the upper limit of concurrent connections. You should also check the server side restriction in postgresql.conf .
- Use PGSimpleDataSource . Depending on the type of application, not using the connection pool (thus creating a connection every time) will not be a problem.
- If you really need a connection pool, just implement your own at the Java level.
EDIT: you can check the number of open connections by simply doing:
SELECT * FROM pg_stat_activity
Each line is a connection (including one of pgAdmin and a query analyzer). If you are sure that the number of connections should not go up to the upper limit (but nevertheless it is), you may have some kind of connection leakage problem.
source share