private WatchService watcher; public void setupWatcher() { watcher = FileSystems.getDefault().newWatchService(); Path toWatch = Paths.get(WATCH_CLASS_DIR); toWatch.register(watcher, StandardWatchEventKinds.ENTRY_CREATE); } public void run() { while (true) { WatchKey key; try { key = watcher.take(); } catch (InterruptedException x) { return; } //Processing of result from watcher } }