• Post Reply Bookmark Topic Watch Topic
  • New Topic

HTML Caching/Performance

 
Rick Crawford
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I have a two-fold question, and wasn't sure whether this should be in JSP/Servlets, Performance or maybe even the Beginners folder! If this question is in the wrong spot, someone please move it to the appropriate place.
I am working on a Java-based website, where the Java code is primarily going to be either JSP or Servlets (no EJB.) We have chosen a method of storing HTML templates in a folder on the webserver. The .jsp will load an appropriate template into memory (using code placed within another Java class) and sending it out to the browser using out.println(). Within this HTML are 'tokens' which we search and replace with data read from the database. In unit testing, this all seems to operate really fast, but I have concerns that under a load this may require some tuning. Maybe there isn't anything to worry about, but nonetheless I am seeking advice.
First, I'd like to post the code I'm using to load the template:

Is this the most efficient way to read a file from a disk with Java?
Secondly, I was toying with the idea of somehow caching the contents of these files so we don't have to continually go back and read the file. I managed to get a little experimental app working that stored the files' contents as Strings within a Hashtable, displaying when it was getting the data from the Hashtable and when it was having to read from the disk:

Of course, for this to do any real good, I figured I'd have to store the instance of the Hashtable in a Singleton fashion. What are the pros and cons of this approach?
I am hoping that someone else had perhaps dealt with something like this before. I would be most grateful for any advice on this problem.
Sincerely,
Rick Crawford
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!