How to call a method every minute using java?

I want to call a method every 1 minute in Java. Please help me deal with this issue.

thank

+3
source share
4 answers

Check out TimerTask, which you can plan for re-execution through Timer.scheduleAtFixedRate().

Alternatively use a quartz trigger if you need something more complex.

+6
source

The ScheduledExecutorService is still not visible among the options.

+2
source
while (true) {
    try {
        Thread.sleep(60 * 1000);
    }
    catch (InterruptedException ie) {
        ie.printStackTrace();
    }
    yourMethod();
}

- , , , Timer TimerTask

-3

:

while (...) { Thread.sleep(60000); //do something }
-3

All Articles