File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create a file on server for ALL clients to use ?

 
Steve Mutanson
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Milind Kolapkar
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Steve Mutanson
Ranch Hand
Posts: 67
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic