Flexible alternatives for locking (selective lock)

前端 未结 1 1858
我在风中等你
我在风中等你 2021-01-24 07:51

I need to resolve situation for equal objects with different memory location (it happens for REST request because of multithreading).

So as part solution I have implemen

相关标签:
1条回答
  • 2021-01-24 08:43

    Guava's Striped lock implementation does what you're doing, but properly (and with far more options regarding weak locks, laziness, semaphores instead of locks etc.).

    It's not that different from what you've done, but you've combined synchronized with locks, whereas a ConcurrentHashMap can get rid of the explicit synchronization (and provide some performance benefits by not locking the whole map every time it's accessed).

    0 讨论(0)
提交回复
热议问题