title: Synchronize on value, not object
body: <p>I want to do something like this in Java</p>
  
  <pre><code>  public void giveMoney(String userId, int money) {
      synchronized (userId) {
  
          Profile p = fetchProfileFromDB(userId);
          p.setMoney(p.getMoney() + userId);
          saveProfileToDB(p);
  
      }
     }
  </code></pre>
  
  <p>But of course, synchronizing on a string is not correct. What's a correct way to do something like this?</p>