@Override
        public void run() {
          synchronized (PollingWatchService.this) {
            for (Map.Entry<Key, Snapshot> entry : snapshots.entrySet()) {
              Key key = entry.getKey();
              Snapshot previousSnapshot = entry.getValue();

              JimfsPath path = (JimfsPath) key.watchable();
              try {
                Snapshot newSnapshot = takeSnapshot(path);
                boolean posted = previousSnapshot.postChanges(newSnapshot, key);
                entry.setValue(newSnapshot);
                if (posted) {
                  key.signal();
                }
              } catch (IOException e) {
                // snapshot failed; assume file does not exist or isn't a directory
                // and cancel the key
                key.cancel();
              }
            }
          }
        }
Map of keys to the most recent directory snapshot for each key.
jimfs/src/main/java/com/google/common/jimfs/PollingWatchService.java