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
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).