File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes ServletContext size constraints? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ServletContext size constraints?" Watch "ServletContext size constraints?" New topic

ServletContext size constraints?

sylvia weller

Joined: Jan 07, 2002
Posts: 29
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.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
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.
sylvia weller

Joined: Jan 07, 2002
Posts: 29
Hi Bill -
Thanks for your helpful response.
I agree. Here's the link:
subject: ServletContext size constraints?
It's not a secret anymore!