Hazelcast IMap - Concurrent updates to the same key, different value

夙愿已清 提交于 2019-12-11 05:28:25

问题


Without testing, because I'm stuck on a train and running out of battery...

I need to determine whether or not Hazelcast's IMap concurrent updates are thread safe updating the same key but different values of that key.

For example:

Let's say I have 2 different threads updating the same IMap key...

For all intents and purposes, this map looks like the following:

  key: {value1: 1, value2: 2}

One thread says,

  "I am updating value1 to 3"

the other thread says (at the same time)

  "I am updating value2 to 4".

How does Hazelcast handle this?

Will the final result look like the following?

  key: {value1: 3, value2: 4}

回答1:


Hazelcast uses partitions. Key is hashed to find the right partition for that entry.

Each partition is single-threaded, there is only one partition-thread handling each partition. So two update for a single key are handled by a single partition-thread.

If both updated keys land in the same partition, these operations will be sequential on a single partition-thread. If each key lands in a different partition - different threads will handle each update.

I don't really understand your notation: key: {value1: 1, value2: 2} -> it looks like a nested map.

Also you say: the same key but different values of that key. -> in a map, each key has a single value only (unless the value is a collection or a map)



来源:https://stackoverflow.com/questions/44854870/hazelcast-imap-concurrent-updates-to-the-same-key-different-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!