2

I want to execute method to run every five minutes and want to release the resources. Can anybody explain how to schedule a loop so that I can execute loop every five minutes or so.

Thanks,

Punith K
  • 656
  • 1
  • 9
  • 26
  • This could be answered in several ways. Could you provide more context? For example is this running in a container environment? Are you using any frameworks already (such as Spring)? Are there any other constraints? – Phil Haigh Sep 08 '14 at 09:18
  • You mean [like this](http://quartz-scheduler.org/)? – Carsten Sep 08 '14 at 09:18
  • I think this may be usedfull for you http://stackoverflow.com/questions/18612656/call-method-after-some-delay-in-java (Using Timer and TimerTask) – Sandun Harshana Sep 08 '14 at 09:25
  • @Phil I'm not using any frameworks as such, since the project I'm working with is real-time one, so I want to release the resources used every five minutes or so. Actually it is OpenCV project where I want to remove the frames captured by camera periodically so that the application runs smoother. #OpenCV4Android – Punith K Sep 08 '14 at 09:39

2 Answers2

2

You can try like this:

Timer timer = new Timer ();
TimerTask sometask = new TimerTask () {
    @Override
    public void run () {
        // code
    }
};

timer.schedule (sometask, 0l, 1000*60*5);
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
  • It looks good answer for my question. Let me put this this way, can I able release the resources after scheduling it. – Punith K Sep 08 '14 at 09:40
1

You can use TimerTask, and Timer to make schedule task, read about these helper-link-1, helper-link-2

Mohamed Yakout
  • 2,868
  • 1
  • 25
  • 45