Punith K
Punith K

Reputation: 666

How to schedule loop in Java

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,

Upvotes: 2

Views: 1467

Answers (2)

Mohamed Yakout
Mohamed Yakout

Reputation: 3036

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

Upvotes: 1

Rahul Tripathi
Rahul Tripathi

Reputation: 172408

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);

Upvotes: 2

Related Questions