I'm developing a Java EE based application using Tomcat as server and MySQL as database. I have configured the connection pool for 50 users.
Now my question is, if at a given time there are 51 users accessing the application (simultaneously), what will happen to the 51th user? (as the application supports only 50 connections at a time)
My requirement is that for the 51st user I need to show a message like " Please access after some other time".
Is this possible?
Connection pool of 50 means you'll have maximum of 50 connection from your WebApp to your DB, it doesn't mean maximum number of user that can connect to your app simultaneously.
Even if a lot of user using your app at the same time, it doesn't mean all of them will be using a connection to DB (for example, idling, viewing static pages, getting data from caches etc).
You didn't mention what connection pool you are using, but I assume you are using any decent library and using it appropriately, e.g call connection.close() every time you finished your query to return the connection to the pool.
If this is the case then don't worry, if the pool is all used up the next user will just be queued until one connection is returned to the pool.
So you can add a timeout to detect this queue time, for example if in 5 to 10 sec DriverManager.getConnection() does not return, assume pool is full and redirect user to static page with that message.
Please do log this event so if you know when your pool is full most of the time then it's time to increase max connections count.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With