File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes A Design doubt from a Greenhorn Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "A Design doubt from a Greenhorn" Watch "A Design doubt from a Greenhorn" New topic
Author

A Design doubt from a Greenhorn

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

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

Save India From Corruption - Anna Hazare.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234


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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30537
    
150

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

Joined: Apr 18, 2009
Posts: 2234

Thank you Jeanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A Design doubt from a Greenhorn