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 }
精彩评论