lazily load JNotify to avoid bloating the guice initialization

This commit is contained in:
Ximin Luo
2014-01-29 20:36:04 +00:00
parent 2bdccef705
commit c000a69f5b

View File

@@ -19,7 +19,8 @@ JNotifyListener {
protected abstract String[] getPathsToWatch(); protected abstract String[] getPathsToWatch();
final private static Throwable loadError = tryLoad(); private static boolean triedLoad = false;
private static Throwable loadError = null;
private static Throwable tryLoad() { private static Throwable tryLoad() {
try { try {
@@ -32,7 +33,11 @@ JNotifyListener {
} }
} }
public static void checkEnabled() throws IOException { public static synchronized void checkEnabled() throws IOException {
if (!triedLoad) {
loadError = tryLoad();
triedLoad = true;
}
if (loadError != null) { if (loadError != null) {
throw new IOException("JNotify not loaded", loadError); throw new IOException("JNotify not loaded", loadError);
} }