Is it valid to lookup a resource (db connection) in the init() method of a servlet?
Cheers
Srini
-
Is it valid? (2 messages)
- Posted by: Srinivasan Ranganathan
- Posted on: August 31 2004 22:59 EDT
Threaded Messages (2)
- Not a ideal suggestion by muhamed rafi on September 01 2004 03:27 EDT
- Not a ideal suggestion by vaheesan selvarajah on September 01 2004 12:01 EDT
-
Not a ideal suggestion[ Go to top ]
- Posted by: muhamed rafi
- Posted on: September 01 2004 03:27 EDT
- in response to Srinivasan Ranganathan
Hi Srini,
When you are developing an tier-architecture, you should not look up a database resource in the servlet, since a web tier should not access the db directly. Insteas you can have a business method in the appliation server which meets ur purpose. This is the ideal way to do, but i'm not sure whether your architecture is having app server or not?
Cheers
Rafi -
Not a ideal suggestion[ Go to top ]
- Posted by: vaheesan selvarajah
- Posted on: September 01 2004 12:01 EDT
- in response to muhamed rafi
Rafi was right on a 3 tier application.
But if you don't have a middle tier in your application then ..
Yes. Using the init method to lookup the DB conn is a good way as that is the method first called in the life cycle of a servlet and during the life time it will not be changed.
Another good strategy would be ti initializa a pool of DB connections rather than a single one. This will give better performance.
Again initializing the pool can be done in the init() method()
More:
http://www.developer.com/tech/article.php/626431
http://www.javaworld.com/javaworld/jw-10-2000/jw-1027-pool.html
good luck!
-vaheesan selvarajah