• Post Reply Bookmark Topic Watch Topic
  • New Topic

javax.servlet.ServletContextListener  RSS feed

 
liliane fahmy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 22526
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
liliane fahmy
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I want example of connection pool and where can I put this connection pool ?
Thanks and best regards
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which servlet container are you using? It likely has documentation about how to set up connection pools; I know Tomcat does.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!