title: Concurrency file system
body: <p>I need to create a File System Manager (more or less) which can read or write data to files. </p>
  
  <p>My problem is how do I handle concurrency?</p>
  
  <p>I can do something like</p>
  
  <pre><code>public class FileSystemManager {
  
      private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
  
      public byte[] read(String path) {
          readWriteLock.readLock().lock();
          try {
              ...
          } finally {
              readWriteLock.readLock().unlock();
          }
      }
      public void write(String path, byte[] data) {
          readWriteLock.writeLock().lock();
          try {
              ...
          } finally {
              readWriteLock.writeLock().unlock();
          }
      }
  }
  </code></pre>
  
  <p>But this would mean all access to the write (for example) will be locked, even if the first invocation is targeting /tmp/file1.txt and the second invocation is targeting /tmp/file2.txt.</p>
  
  <p>Any ideas how to go about this?</p>