aspose file tools
The moose likes JDBC and Relational Databases 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


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32301
    
213

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



[OCA 8 book] [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
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

I prefer Java Quartz for scheduling solutions.


[OCA 8 Book] [Blog]
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32301
    
213

Scott,
For anything complex, I prefer Quartz as well. For scheduling one or two simple jobs - I go with TimerTask.
 
Consider Paul's rocket mass heater.
 
subject: How can i run a particular code for every 10 minutes
 
It's not a secret anymore!