Merge remote-tracking branch 'origin/master'

This commit is contained in:
danielshaya
2015-05-20 18:09:55 +01:00
2 changed files with 28 additions and 12 deletions
@@ -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();
}