This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
Hi - I am writing an uncomplicated servlet-based application which queries one db table and retrieves a subset of its data for JSP/HTML display. I was thinking about saving the entire table (a few thousand rows) to the ServletContext at application startup time. Then, subsequent retrievals could run against this saved version. I'm pretty sure this would be _much_ faster than doing dbio for each retrieval. So here's my question - is there any reason not to save 'lots' of data - thousands of lines - on the ServletContext? and why? I actually don't know anything about how memory is allocated and how much is available, within the servlet container (tomcat in my case). I just naively came up with this idea and want to know if it was a bad or good one. Also, if anyone knows of a good reference on this topic please let me know. Thanks. Sylvia
I have never seen something like that done before, normally ServletContext is relatively small and restricted to parameters for a particular "web application". If faced with the problem, I would keep the data as a static variable in the servlet class or as part of a "singleton" helper class. That would make it easier to regenerate if the database changed. I think you should not try to keep the data as a ResultSet or other JDBC entity since that might hang on to additional resources. Instead, grab it to some convenient Java collection or write your own helper class to hold the data in some compact form. Bill
Joined: Jan 07, 2002
Hi Bill - Thanks for your helpful response. Sylvia