Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can i run a particular code for every 10 minutes

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Praveen Rajendran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could let Java handle it for you. Look at the TimerTask and Timer classes.

 
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 all . Its easy to go for Timer and TimerTask .
 
Scott Selikoff
author
Saloon Keeper
Posts: 4020
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer Java Quartz for scheduling solutions.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Scott,
For anything complex, I prefer Quartz as well. For scheduling one or two simple jobs - I go with TimerTask.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic