开发者

how to call method in every one minute using java?

开发者 https://www.devze.com 2023-02-15 21:21 出处:网络
I want to call me开发者_Python百科thod in every 1 min in Java.Please help me to sort out this problem.

I want to call me开发者_Python百科thod in every 1 min in Java. Please help me to sort out this problem.

Thanks


Check out TimerTask which you can schedule for repeated execution via Timer.scheduleAtFixedRate().

Alternatively use a quartz trigger if you want something a bit more sophisticated.


Still cannot see ScheduledExecutorService among the variants.


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

Something as simple as this, or if you need accurate precision, you've to use Timer and TimerTask


one simple way of doing it is

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

精彩评论

暂无评论...
验证码 换一张
取 消