title: How to watch a complete file system for changes in Java?
body: <p><strong>Problem description</strong><br />
  I would like to watch a complete file system for changes. I'm talking about watching changes in a directory recursively. So, when watching a directory (or a whole file system) all changes in sub-directories need to be captured too. The application needs to be able to track all changes by getting notified.</p>
  
  <p><strong>Java's WatchService isn't suitable</strong><br />
  Java already <a href="https://docs.oracle.com/javase/tutorial/essential/io/notification.html#overview" rel="nofollow">has</a> a <code>WatchService</code> feature, which allows you to monitor a directory for changes. The problem is however, that this isn't a recursive process as far as I know, thus you can't use this to monitor all changes in the root directory of a file system.</p>
  
  <p><strong>Watching all sub-directories explicitly</strong><br />
  A solution I've thought of would be to register each directory inside the specified root directory explicitly. The problem with this is however, that walking through, and registering these directories is very resource expensive on a system with more than a million sub-directories. This is because the system would need to go through the whole file system recursively to only register all directories in the first place. The performance impact of this feature would be too big, if it's even possible without crashing the application.</p>
  
  <p><strong>Logical solution</strong><br />
  I would assume an operating system would fire/call some sort of event when anything is changed on the file system, that an application is able to listen to. I did however, not find anything like this yet. This would allow the application to listen to all changes without the need to register all sub-directories explicitly. Thus the performance impact with such a method would be minimal.</p>
  
  <p><strong>Question</strong><br />
  Is watching a whole file system, or watching a directory recursively possible in Java, and how would this be achieved?</p>