title: How does Java Synchronized compare locked objects?
body: <p>I want to lock an object over multiple API requests such that only one request per user can enter a block of code.</p>
  
  <p>Does <code>synchronized(obj)</code> lock based on the object's reference or its <code>hashCode()</code> function?</p>
  
  <p>I.e. could I do:</p>
  
  <pre><code>synchronized("asdf") {
      doSomethingNifty();
  }
  </code></pre>
  
  <p>Here "asdf" has a unique hash but no unique reference.</p>