title: How to acquire a lock by a key
body: <p>What is the best way to prevent concurrent update of one record in a key-value set without locking the entire set? Semantically, I'm looking for some kind of locking by a key (ideally, Java implementation, but not necessarily):</p>
  
  <pre><code>interface LockByKey {
     void lock(String key); // acquire an exclusive lock for a key   
     void unlock(String key); // release lock for a key
  }
  </code></pre>
  
  <p>This lock is intended to synchronize an access to a remote store, so some synchronized Java collection is not an option.</p>