I’ve been approached by a programmer that has background in Oracle forms and is moving into the Java realm. He asked me a question that I didn’t have a good answer for. Instead of answering that; I always do it that way or that’s how I was taught. I figured I’d do some research.
Question: With Java multi-thread capabilities; why don’t you setup a JDBC connection to the database for each user, each on it’s own thread? Instead of setting up a connection pool and applying security to which users can access the pool?
A connection pool scales better. If you have a dedicated connection per user, you will need 50 connections for 50 users. With a pool, you can probably do with something like 10 – 20 connections to handle the 50 users (depending on the use case). Now take a look at a bigger group and think about handling 500, 5000 or 50000 users and you will see that the 1 connection per user model does not scale.
With a connection pool (and a thread pool), each request will still be handled by one thread and by one database connection, but they will be taken from a pool instead of a dedicated one per user.