From 0c2e624f108087c4f073913755bc07cc33c3aaad Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Thu, 21 Jan 2016 12:53:48 +0100 Subject: [PATCH] (Probably) Fix bug where unclosed WatchServices cause inotify limit to fill upp. Also cache the values for a minor speedup. --- .../massivecore/store/DriverFlatfile.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/com/massivecraft/massivecore/store/DriverFlatfile.java b/src/com/massivecraft/massivecore/store/DriverFlatfile.java index 40c199c2..c5c15a77 100644 --- a/src/com/massivecraft/massivecore/store/DriverFlatfile.java +++ b/src/com/massivecraft/massivecore/store/DriverFlatfile.java @@ -3,6 +3,7 @@ package com.massivecraft.massivecore.store; import java.io.File; import java.io.IOException; import java.nio.file.FileSystems; +import java.nio.file.WatchService; import java.util.AbstractMap.SimpleEntry; import java.util.ArrayList; import java.util.Collection; @@ -218,12 +219,15 @@ public class DriverFlatfile extends DriverAbstract file.delete(); } - @Override - public boolean supportsPusher() + private boolean supportsPusher = this.supportsPusherCalc(); + private boolean supportsPusherCalc() { try { - return ! ( FileSystems.getDefault().newWatchService().getClass().getName().equals("sun.nio.fs.PollingWatchService")); + WatchService watchService = FileSystems.getDefault().newWatchService(); + boolean ret = ! watchService.getClass().getName().equals("sun.nio.fs.PollingWatchService"); + watchService.close(); + return ret; } catch (IOException e) { @@ -231,6 +235,12 @@ public class DriverFlatfile extends DriverAbstract } } + @Override + public boolean supportsPusher() + { + return this.supportsPusher; + } + @Override public PusherColl getPusher(Coll coll) {