Forums Register Login

javax.servlet.ServletContextListener

+Pie Number of slices to send: Send
I know that javax.servlet.ServletContextListener is called when the application started(after deployment)
My question is :when i have huge application which use it more then 100 users at the same time,I can make the connection of DataBase in the servletContextListener or
it will be better if I make it when the user login and put it in session scope?which improve the performance ?
Please answer me
Thanks and best regards
+Pie Number of slices to send: Send
You should have one and only one connection to the database and funnel your application's data needs through that pipe. See Separation of Concerns. Your users should log into your application but you should not have one database connection per user. Neither should you have one database connection per session.
+Pie Number of slices to send: Send
As Roger says, both of your options are bad choices. The typical design is to have a connection pool; when your application needs to access data from the database it does this:

1. Get a connection from the pool

2. Use that connection to get the data your application requires

3. Return the connection to the pool

Your code should not keep the connection any longer than necessary.
+Pie Number of slices to send: Send
Start with a connection pool of ONE connection. Make that work well. Then increase the number of connections in the pool as needed. For 100 users, I don't see you needing more than one, but...
+Pie Number of slices to send: Send
So I want example of connection pool and where can I put this connection pool ?
Thanks and best regards
+Pie Number of slices to send: Send
Which servlet container are you using? It likely has documentation about how to set up connection pools; I know Tomcat does.
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 737 times.
Similar Threads
Calling EJB Bean with WebSphere application server Scheduler
Running a Socket server process in Tomcat
Cannot find ServletContextListener
passing intialisation values to an application
HttpSessionAttributeListener and HttpSessionBindingListener
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:56:03.