I am writing a distributed application using Hazelcast(JCache standard) for caching.
I have an use case where I should put a lock on specific key in a cluster to prevent from calls during updating.
- thread1: get item1 for a config change(put a lock)
- thread2: get item1 for an update.
- thread2: put item1 with update and a new timestamp.
- thread1: put item1 with an old value and timestamp
I know EhCache has something very similar, it's called acquireReadLockOnKey(Object key).
How can I achieve that kind of lock using JCache and/or Hazelcast?
Look at Entry Processor which performs update operations on cache entries in an atomic and lock-free manner.