Java: Synchronizing on primitives?

前端 未结 10 1830
小鲜肉
小鲜肉 2021-02-01 21:13

In our system, we have a method that will do some work when it\'s called with a certain ID:

public void doWork(long id) { /* ... */ }

Now, this

10条回答
  •  清歌不尽
    2021-02-01 22:06

    You can try something with a ReentrantLock, such that you have a Map. Now after lock.release() You can test lock.hasQueuedThreads(). If that returns false you can remove it from the Map.

提交回复
热议问题