• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTML Caching/Performance

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
There’s no place like 127.0.0.1. But I'll always remember this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic