Skip to content

Instantly share code, notes, and snippets.

@camerondavison
Created September 23, 2014 23:03
Show Gist options
  • Save camerondavison/448eb429c2c4c20f557f to your computer and use it in GitHub Desktop.
Save camerondavison/448eb429c2c4c20f557f to your computer and use it in GitHub Desktop.
final Semaphore s = new Semaphore(10);
final Stopwatch w = Stopwatch.createStarted();
final File t = Files.createTempDir();
try {
for (int i = 0; i < 10000; i++) {
s.acquire();
final RandomAccessFile file = new RandomAccessFile(new File(t, "f" + i + ".txt"), "rw");
file.write("HELLO WORLD".getBytes(Charsets.UTF_8));
file.close();
s.release();
}
w.stop();
System.out.println("Done in " + w);
} finally {
for (File file : Files.fileTreeTraverser().breadthFirstTraversal(t)) {
file.delete();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment