Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A Design doubt from a Greenhorn

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Design doubt from a Greenhorn

Need to create a Thread that will run for every 15 seconds and update the Cache .

so that the servlets will pick up the data from this cache instead of querying database.


what is the appropiate place to create this Thread ?
For this I was thinking in this way :

shall i start this Thread inside a ServletContextListener ?? will this be a appropiate place ?

Can any one suggest me a better approach or tell me if I am missing something.

Any help is really appreciated
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi,
I'd take a different approach - when the cache is called see if the data is 15 seconds old and if so, get new data. That way the database wouldn't need to be called if there is no activity for 15 seconds.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the prompt reply Jeanne ,

what would you suggest if the Thread needs to run for every 5 seconds . Is my approach correct .
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34671
367
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ravi Pavanv wrote:What would you suggest if the Thread needs to run for every 5 seconds . Is my approach correct .

I'd use a Timer/Scheduler if I had to run something every 5 seconds. I wouldn't do that here though.

As for whether your approach is correct - it depends on the usage patterns of your app. It's not a right or wrong type of thing.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jeanne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic