title: Java: nio WatchService - Can't detect second file creation. Why?
body: <p>i am trying to detect file creation in a folder but <code>WatchService</code> can't detect second file creation. it stucks at <code>key = watcher.take()</code>. Any idea why? I am using Ubuntu 11.04 x86.</p>
  
  <pre><code>private void watchWorkingDirectory() {
      try {
          WatchService watcher = FileSystems.getDefault().newWatchService();
          WatchKey key;
          key = Paths.get(tailSource, "").register(watcher, ENTRY_CREATE);
  
          for (;;) {
  
              System.err.println("Watching current working directory...............................................");
              // wait for key to be signalled
              key = watcher.take();
  
              System.out.println("Event detected:");
  
  
              for (WatchEvent&lt;?&gt; event : key.pollEvents()) {
                  WatchEvent.Kind&lt;?&gt; kind = event.kind();
  
                  if (kind == ENTRY_CREATE) {
                      tailSource = event.context().toString();
                      System.out.println(tailSource);
                      File file = new File(tailSource);
                      BufferedReader br = new BufferedReader(new FileReader(file));
                      System.out.println(br.readLine());
                      tailer = new Tailer(file, tListener, 1, false);
                      (new Thread(tailer)).start();
                  }
              }
          }
  
      } catch (IOException | InterruptedException e) {
          System.out.println(e.getMessage());
      }
  }
  </code></pre>
  
  <p>}</p>