@@ -136,34 +136,37 @@ public Set<String> retrieveSameURIs(String uri) {
136
136
LOGGER .error ("Exception while waiting for read mutex. Returning null." , e );
137
137
return null ;
138
138
}
139
- // Check again that nobody already added the uri
140
- if (uriSetIdMapping .containsKey (uri )) {
141
- // use the cached result
142
- int setId = uriSetIdMapping .get (uri );
143
- if (setId != ENTITY_NOT_FOUND ) {
144
- result = sets .get (setId );
145
- } else {
146
- result = null ;
147
- }
148
- } else {
149
- if (result != null ) {
150
- mergeSetIntoCache (result );
139
+ try {
140
+ // Check again that nobody already added the uri
141
+ if (uriSetIdMapping .containsKey (uri )) {
142
+ // use the cached result
143
+ int setId = uriSetIdMapping .get (uri );
144
+ if (setId != ENTITY_NOT_FOUND ) {
145
+ result = sets .get (setId );
146
+ } else {
147
+ result = null ;
148
+ }
151
149
} else {
152
- uriSetIdMapping .put (uri , ENTITY_NOT_FOUND );
153
- }
154
- ++cacheChanges ;
155
- if ((forceStorageAfterChanges > 0 ) && (cacheChanges >= forceStorageAfterChanges )) {
156
- LOGGER .info ("Storing the cache has been forced..." );
157
- try {
158
- performCacheStorage ();
159
- } catch (IOException e ) {
160
- LOGGER .error ("Exception while writing cache to file. Aborting." , e );
150
+ if (result != null ) {
151
+ mergeSetIntoCache (result );
152
+ } else {
153
+ uriSetIdMapping .put (uri , ENTITY_NOT_FOUND );
154
+ }
155
+ ++cacheChanges ;
156
+ if ((forceStorageAfterChanges > 0 ) && (cacheChanges >= forceStorageAfterChanges )) {
157
+ LOGGER .info ("Storing the cache has been forced..." );
158
+ try {
159
+ performCacheStorage ();
160
+ } catch (IOException e ) {
161
+ LOGGER .error ("Exception while writing cache to file. Aborting." , e );
162
+ }
161
163
}
162
164
}
165
+ } finally {
166
+ // The last one will be released at the end
167
+ cacheReadMutex .release (MAX_CONCURRENT_READERS - 1 );
168
+ cacheWriteMutex .release ();
163
169
}
164
- // The last one will be released at the end
165
- cacheReadMutex .release (MAX_CONCURRENT_READERS - 1 );
166
- cacheWriteMutex .release ();
167
170
}
168
171
cacheReadMutex .release ();
169
172
return result ;
@@ -211,8 +214,9 @@ public void storeCache() {
211
214
performCacheStorage ();
212
215
} catch (IOException e ) {
213
216
LOGGER .error ("Exception while writing cache to file. Aborting." , e );
217
+ } finally {
218
+ cacheWriteMutex .release ();
214
219
}
215
- cacheWriteMutex .release ();
216
220
}
217
221
218
222
private void performCacheStorage () throws IOException {
0 commit comments