• 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

Loading a file in a servlet at run time

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a simple servlet which reads an xml file in its init method.

This XML file has some name value pairs.

These are read in a hashmap in the init method.

This is a global hashmap which is used in the service method for some processing and logic building.

Without shutting down the servlet, if an admin changes this xml file which was read in the init method, how will I reload/refresh the hashmap at run time so that the newly added values can be used for the forthcoming requests.

Thanks
Regards
Jasmina
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the code that reads the xml file in a separate method - called from init and also callable from other methods. If you grab the timestamp on the file when init reads it, it is pretty simple to compare the current file's timestamp with the one that corresponds to the hashmap data and decide whether or not to re-read the file.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic