Java synchronizing based on a parameter (named mutex/lock)

后端 未结 8 1794
逝去的感伤
逝去的感伤 2020-12-05 02:50

I\'m looking for a way to synchronize a method based on the parameter it receives, something like this:

public synchronized void doSomething(name){
//some co         


        
8条回答
  •  醉酒成梦
    2020-12-05 03:07

    I've created a tokenProvider based on the IdMutexProvider of McDowell. The manager uses a WeakHashMap which takes care of cleaning up unused locks.

    You could find my implementation here.

提交回复
热议问题