开发者

how to call method in every one minute using java?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜