mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -8,6 +8,7 @@ import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -136,7 +137,24 @@ public class FilePerKeyMap implements Map<String, String>, Closeable {
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
getFiles().forEach(this::deleteFile);
|
||||
AtomicInteger count = new AtomicInteger();
|
||||
Stream<Path> files = getFiles();
|
||||
files.forEach((path) -> {
|
||||
try {
|
||||
deleteFile(path);
|
||||
} catch (Exception e) {
|
||||
count.incrementAndGet();
|
||||
// ignored at afirst.
|
||||
}
|
||||
});
|
||||
if (count.intValue() > 0) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().isInterrupted();
|
||||
}
|
||||
getFiles().forEach(this::deleteFile);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -125,18 +125,16 @@ public class FilePerKeyMapTest {
|
||||
String value = sb.toString();
|
||||
|
||||
//small warm-up
|
||||
for (int i = 0; i < 10; i++) {
|
||||
map.put("big file", value);
|
||||
for (int j = -1; j < 3; j++) {
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
int iterations = 50;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
map.put("big file-" + i, value);
|
||||
}
|
||||
if (j >= 0)
|
||||
System.out.println("Time to update " + iterations + " puts " + (System.currentTimeMillis() - time) + " ms.");
|
||||
}
|
||||
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
int iterations = 50;
|
||||
for (int i = 0; i < iterations; i++) {
|
||||
map.put("big file", value);
|
||||
}
|
||||
System.out.println("Time to update " + iterations + " iterations " + (System.currentTimeMillis() - time));
|
||||
|
||||
map.clear();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user