mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Improve closing of resources on windows system.
This commit is contained in:
Regular → Executable
+8
-14
@@ -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) {
|
||||
|
||||
Regular → Executable
+1
-1
@@ -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; ) {
|
||||
|
||||
Reference in New Issue
Block a user