aspose file tools*
The moose likes JDBC and the fly likes How can i run a particular  code for every 10 minutes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How can i run a particular  code for every 10 minutes" Watch "How can i run a particular  code for every 10 minutes" New topic
Author

How can i run a particular code for every 10 minutes

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi

I am trying to cache the data to reduce the hits to Daabase.

So for this i am storing the data in application scope .

Please tell me how can i for every 10 minutes clear my Application data and put new data into it.
How can i do this for every 10 minutes .

Thanks .


Save India From Corruption - Anna Hazare.
Praveen Rajendran
Greenhorn

Joined: Dec 25, 2009
Posts: 21
Hi Ravi,
I guess you can write your caching program in a servlet such that the cache function will be done in a while loop with always true condition. Also the timing interval of caching can be done by using Thread.sleep(time) method defining the interval time in milli seconds. The servlet can be configured to trigger on application startup using web.xml.
Let me know if this makes sense.


Thanks & Regards,
Praveen
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Or you could let Java handle it for you. Look at the TimerTask and Timer classes.



[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

Thank you all . Its easy to go for Timer and TimerTask .
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3704
    
    5

I prefer Java Quartz for scheduling solutions.


My Blog: Down Home Country Coding with Scott Selikoff
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150

Scott,
For anything complex, I prefer Quartz as well. For scheduling one or two simple jobs - I go with TimerTask.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can i run a particular code for every 10 minutes