Search code examples
ignite

Should I add lock to ignite cache as it will be read/write in different thread?


I have two thread, each thread add/modify the values of ignite cache, it likes:

cache = ignite.getOrCreateCache("IniteTestCache")
valMap = cache.get(key)

get the item in value valMap(java map), handle it, and remove it and then update the cache: cache.put(key, a) to let the valMap items down,

in another thread:

cache = ignite.getOrCreateCache("IniteTestCache")
valMap = cache.get(key)

add new items to valMap, and put it back to cache cache.put(key, a) to add new items to it

Questions:
As i manipulation on the same cache with same key, should i add lock to as:

lock()
value=cache.get(key)
modification to value
cache.put(key,value)
unlock()

or I use Atomic to the cache config to make ignite do this automatically for me, or I need use TRANSACTIONAL to cache, and add lock to cache?

or there are some more better way to avoid lock to achive high performance?


Solution

  • I would recommend using EntryProcessor for this use case: https://apacheignite.readme.io/docs/jcache#entryprocessor