Your code seems to be one big race condition. Only one servlet instance is used for multiple requests. As a result, on concurrent requests, your current code can and will leak connections.
When concurrent requests are executed, each of them will create a connection and assign it to the same instance variable, so one or more connections will be lost and remain open. The use of that DBConnection.getConnection
/DBConnection.closeConnection
suggests that you are potentially leaking connections there as well.
Please stop using fields to keep your connection
and statement
, and make these local variables instead. Also consider using try-with-resources to properly close connections, and consider using a DataSource
directly instead of using that (probably unnecessary) abstraction of DBConnection
.