Код: Выделить всё
@Service
public class MyService {
private Map cache = null;
private ReentrantLock reentrantLock = new ReentrantLock();
public void rebuildCache(){
try {
reentrantLock.lock();
cache = new ConcurrentHashMap();
... //processing time consuming stuff and building up the cache
}finally {
reentrantLock.unlock();
}
}
public Value getValue(Key key){
while (lock.isLocked()){}
return cache.get(key);
}
...
}
Код: Выделить всё
while (reentrantLock.isLocked()){}
Подробнее здесь: https://stackoverflow.com/questions/328 ... or-waiting
Мобильная версия