for (Integer id : ids) {
int result = doSomething(id);
while (result == someValue) {
Thread.sleep(10 * 1000);
result = doSomething(id);
}
int anotherResult = doAnotherThing(result);
while (anotherResult == anotherValue) {
Thread.sleep(10 * 1000);
anotherResult = doAnotherThing(result);
}
}
感觉两个 sleep 用在这里不太合适也不太优雅,必须用 try catch 把相应的代码块给包起来
考虑用 ScheduledExecutorService 或者 delayQueue 实现,但是感觉前者需要另外开一个线程不太合适,因为我只需要一个线程来执行这个逻辑
V 友们有更好的解决办法吗