This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
When users access servlet "TicketBookingServlet", I want "TicketBookingServlet" to access database and get ALL the information about city names and flight info, then in the picklist I want these values to be poped so users can choose. However, this requires every session opens database connection, although I can use some connection pooing method to improve the performance. I want to just do this database for ONE time and save the information into a file so that the following client access should read that file. Does this make sense in terms of saving database connection ? If yes, then how can I let my servlet do this ?
You can use setAttribute method of ServletContext and store file in to ServletContext so any message or any session will access it And plus you can start one daemon thread on server so when ever DB will getupdate it will update that file ....in this way you can save your DB trips...
M I L I N D
Joined: Apr 15, 2003
Originally posted by Milind Kolapkar: You can use setAttribute method of ServletContext and store file in to ServletContext so any message or any session will access it And plus you can start one daemon thread on server so when ever DB will getupdate it will update that file ....in this way you can save your DB trips...
if I choose to use ServletContext and setAttribute on it, where should I put the DB query (only for once) and "setAttribute" code ? should I put in in the "init()" method to do it ?
Seems to me you want to provide for updating that information on some sort of schedule so using init is not a good idea. After all, your same servlet instance may stay up for weeks. How about a helper class (JavaBean?) to hold the schedule (or a pointer to the file) and a timestamp indicating when the last real database lookup was. Then if you get a request and the data is no longer fresh you can do a query. The instance of the helper could be held in the ServletContext as suggested. Bill [ April 16, 2003: Message edited by: William Brogden ]