import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
*
* @see java.util.concurrent.Executors#newCachedThreadPool()
*/
- private static final Executor FUTURE_RUNNER = new ThreadPoolExecutor(0,
- 5, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(),
+ private static final ExecutorService FUTURE_RUNNER = new ThreadPoolExecutor(
+ 0, 5, 30L, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(),
runnable -> {
Thread t = new Thread(runnable,
"JGit-FileStoreAttributeReader-" //$NON-NLS-1$
* small keep-alive time to avoid delays on shut-down.
* </p>
*/
- private static final Executor SAVE_RUNNER = new ThreadPoolExecutor(0, 1,
- 1L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),
+ private static final ExecutorService SAVE_RUNNER = new ThreadPoolExecutor(
+ 0, 1, 1L, TimeUnit.MILLISECONDS,
+ new LinkedBlockingQueue<Runnable>(),
runnable -> {
Thread t = new Thread(runnable,
"JGit-FileStoreAttributeWriter-" //$NON-NLS-1$
return t;
});
+ static {
+ // Shut down the SAVE_RUNNER on System.exit()
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try {
+ SAVE_RUNNER.shutdownNow();
+ SAVE_RUNNER.awaitTermination(100, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ // Ignore; we're shutting down
+ }
+ }));
+ }
+
/**
* Whether FileStore attributes should be determined asynchronously
*
return null;
}
// fall through and return fallback
- } catch (IOException | InterruptedException
- | ExecutionException | CancellationException e) {
+ } catch (IOException | ExecutionException | CancellationException e) {
LOG.error(e.getMessage(), e);
} catch (TimeoutException | SecurityException e) {
// use fallback
+ } catch (InterruptedException e) {
+ LOG.error(e.getMessage(), e);
+ Thread.currentThread().interrupt();
}
LOG.debug("{}: use fallback timestamp resolution for directory {}", //$NON-NLS-1$
Thread.currentThread(), dir);
Path probe = dir.resolve(".probe-" + UUID.randomUUID()); //$NON-NLS-1$
Instant end = Instant.now().plusSeconds(3);
try {
+ probe.toFile().deleteOnExit();
Files.createFile(probe);
do {
n++;
}
Path probe = dir.resolve(".probe-" + UUID.randomUUID()); //$NON-NLS-1$
try {
+ probe.toFile().deleteOnExit();
Files.createFile(probe);
Duration fsResolution = getFsResolution(s, dir, probe);
Duration clockResolution = measureClockResolution();