title: Equivalence lock in Scala/Java?
body: <p>Is there anyway to lock on the object equality instead of referential equality in Scala/Java e.g.</p>
  
  <pre><code>def run[A](id: A) = id.synchronized {
    println(s"Processing $id")
    Thread.sleep(5000)
    println(s"Done processing $id")
  }
  
  Seq(1, 1, 2, 3, 1).par.foreach(run)
  </code></pre>
  
  <p>I want this to print something like:</p>
  
  <pre><code>Processing 3
  Processing 1
  Processing 2
  // 5 seconds later
  Done processing 1
  Done processing 2
  Done processing 3
  Processing 1
  // 5 seconds later
  Done processing 1
  Processing 1
  // 5 seconds later
  Done processing 1
  </code></pre>