private val lockByKey = new java.util.concurrent.ConcurrentHashMap[Any, Object] ... locks.get(key)This is what I actually typed:
private def lockByKey = new java.util.concurrent.ConcurrentHashMap[Any, Object] ... locks.get(key)Because I put 'def lockByKey' instead of 'val lockByKey' I created myself a function that creates a new ConcurrentHashMap every time it gets called instead of a single instance. Scala allows leaving out brackets in many cases so code like lockByKey.get(...) compiled fine, but as every access was creating a new map things didn't work entirely correctly.
Thankfully unit tests of basic functionality (eg ability to get the same value back twice) caught that something was awry and I was able to identfy that I had cleverly created a factory function rather than a static instance. Thank god for unit tests ;)