• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to change values in servlet context

 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi... all
I m indulge in a project in which I have saved some values in servlet context that would be work for all user. and these values are picked from database.Servlet which save these values in servlet context, is loaded when server gets start.
my problem is that if any time I change the values in database then I 'll have to restart the server agin.
how can avoid this.
I m using tomcat 4.1 /oracle/wion 2000
please give me a suggession

Thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a basic cache problem - every time the backing store is updated, the cache needs to be invalidated. Maybe your code that changes the values can access a special URL in your web app that tells it to update its cache.
 
Vijay Kumar
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for it.
but my problem is that if there is any updation in database then the value saved in servlet context should get updated.If I restart the the server. then the servlet loaded agin with the updated values , but I want that without restarting the server servlet context should get updated.
thanks
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your servlet saves the values in the context upon startup (using getServletContext().setAttribute() I'm assuming), why not do the same whenever the data changes?

-Yuriy
 
Yuriy Zilbergleyt
Ranch Hand
Posts: 429
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^ note that this will not work if your application is distributed, since you'll have seperate ServletContexts.

-Yuriy
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

but I want that without restarting the server servlet context should get updated.


That's why I suggested that the code that updates the value hits a special URL (in the same servlet context as your cache) that causes the value to be updated. If the change happens in code that's outside your control you may need to use a trigger on that DB table (although I wouldn't know how that could access a URL).
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic