second part of fix for bug 3330: ensure that only one thread tries to load persistent declination values at a time

This commit is contained in:
Axel Uhl committed 2015-10-15 19:11:53 +02:00
1 parent 1386e76341
commit 63ae032bfd
1 file changed
+9 -3
@@ -101,9 +101,15 @@ public class DeclinationServiceImpl implements DeclinationService {
private QuadTree<Declination> getYearStore(int year) throws IOException, ParseException {
QuadTree<Declination> result = yearStore.get(year);
if (result == null) {
result = persistentStore.getStoredDeclinations(year);
if (result != null) {
yearStore.put(year, result);
synchronized (this) {
// make sure we only trigger one invocation of persistentStore.getStoredDeclinations(year) even for multiple threads
result = yearStore.get(year);
if (result == null) {
result = persistentStore.getStoredDeclinations(year);
if (result != null) {
yearStore.put(year, result);
}
}
}
}
return result;