![]() |
![]() |
||||
No, physical database connections will only free up if the java object is destroyed.
A better solution is to use a connection pool (see DBCP), and close connections when you are finished with them. This also provides a large performance boost, because connections can be re-used.
In a local development environment, setting a connection pool to allow a maximum of 100 connections is ok, because you are the only user of the database. However, on a server, this can have disastrous effects.
Imagine if 50 applications were accessing the same database server, and each of them had 100 concurrent connections. That's 5000 connections in total. Using connections in this way wastes resources such as network sockets, file handles, and RAM.
Most sites should have a minimum of 2-3 connections and a maximum of 8-15. A site allowing 15 concurrent connections would be a very busy site, handling 15 concurrent page accesses (approx 200-400 concurrent users).
In a busy CMS, handling over 50 websites, it would make sense to have a higher number than 15 connections. In this case 15-25 is a more sensible limit.
Allowing too many connections also hides problems during development. If you are the only user accessing your development server, try setting your connection limit to between 2 and 5. If there is a connection leak (connections being opened, but not closed again), you should be able to find out quickly, before risking deployment to the production environment.
This wiki has many examples of using Database Connection Pools, using the Apache Commons DBCP mechanism which is built into Tomcat.
The following pages are a good place to start: