List of usage examples for org.eclipse.jdt.internal.core.search.indexing ReadWriteMonitor exitWriteEnterRead
public synchronized void exitWriteEnterRead()
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
/** * Commit all index memory changes to disk *//*from w w w . ja v a 2 s . com*/ public void saveIndexes() { // only save cached indexes... the rest were not modified ArrayList toSave = new ArrayList(); synchronized (this) { Object[] valueTable = this.indexes.valueTable; for (int i = 0, l = valueTable.length; i < l; i++) { Index index = (Index) valueTable[i]; if (index != null) toSave.add(index); } } boolean allSaved = true; for (int i = 0, length = toSave.size(); i < length; i++) { Index index = (Index) toSave.get(i); ReadWriteMonitor monitor = index.monitor; if (monitor == null) continue; // index got deleted since acquired try { // take read lock before checking if index has changed // don't take write lock yet since it can cause a deadlock (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50571) monitor.enterRead(); if (index.hasChanged()) { if (monitor.exitReadEnterWrite()) { try { saveIndex(index); } catch (IOException e) { if (VERBOSE) { Util.verbose("-> got the following exception while saving:", System.err); //$NON-NLS-1$ e.printStackTrace(); } allSaved = false; } finally { monitor.exitWriteEnterRead(); } } else { allSaved = false; } } } finally { monitor.exitRead(); } } if (this.participantsContainers != null && this.participantUpdated) { writeParticipantsIndexNamesFile(); this.participantUpdated = false; } this.needToSave = !allSaved; }