
您可以让Runnable安排其“下次运行”。
如,
class Task implements Runnable { private final ScheduledExecutorService service; public Task(ScheduledExecutorService service){ this.service = service; } public void run(){ try{ //do stuff }finally{ //Prevent this task from stalling due to RuntimeExceptions. long untilNextInvocation = //calculate how many ms to next launch service.schedule(new Task(service),untilNextInvocation,TimeUnit.MILLISECONDS); } }}欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)