Improve closing of resources on windows system.

This commit is contained in:
Peter Lawrey
2014-11-13 00:09:11 +00:00
parent 5839bd692a
commit fa4ecf828d
7 changed files with 25 additions and 468 deletions
+8 -14
View File
@@ -23,38 +23,31 @@ import org.slf4j.LoggerFactory;
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.ArrayList;
import java.util.List;
final class CloseablesManager implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(CloseablesManager.class.getName());
private final Set<Closeable> closeables = new LinkedHashSet<Closeable>();
private final List<Closeable> closeables = new ArrayList<>();
public synchronized void add(Closeable closeable) {
if (closeable == null)
throw new NullPointerException();
closeables.add(closeable);
if (!closeables.contains(closeable))
closeables.add(closeable);
}
public synchronized void close(Closeable closeable) throws IOException {
for (Iterator<Closeable> iterator = closeables.iterator(); iterator.hasNext(); ) {
if (iterator.next() == closeable)
iterator.remove();
}
closeables.remove(closeable);
closeable.close();
}
public synchronized void closeQuietly(Closeable closeable) {
try {
close(closeable);
} catch (IllegalStateException e) {
// this can occur if already closed ( for example closed is called from another thread )
} catch (IOException e) {
LOG.error("", e);
}
@@ -63,7 +56,8 @@ final class CloseablesManager implements Closeable {
@Override
public synchronized void close() throws IOException {
IOException ex = null;
for (Closeable closeable : closeables) {
for (int i = closeables.size() - 1; i >= 0; i--) {
Closeable closeable = closeables.get(i);
try {
closeable.close();
} catch (IOException e) {
+1 -1
View File
@@ -945,7 +945,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, KI>,
}
}
private V putWithoutLock(ThreadLocalCopies copies, MKI metaKeyInterop, KI keyInterop, K key, V value, long hash2, boolean replaceIfPresent) {
V putWithoutLock(ThreadLocalCopies copies, MKI metaKeyInterop, KI keyInterop, K key, V value, long hash2, boolean replaceIfPresent) {
long keySize = metaKeyInterop.size(keyInterop, key);
hashLookup.startSearch(hash2);
for (long pos; (pos = hashLookup.nextPos()) >= 0L; ) {