Hazelcast IMap-并发更新到相同的键,但值不同 [英] Hazelcast IMap - Concurrent updates to the same key, different value
问题描述
未经测试,因为我被困在火车上,电池没电了...
Without testing, because I'm stuck on a train and running out of battery...
我需要确定Hazelcast的IMap并发更新是否是线程安全的,以更新同一密钥但该密钥的值不同.
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.
例如:
假设我有2个不同的线程更新同一个IMap密钥...
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}
一个线程说,
"I am updating value1 to 3"
另一个线程说(同时)
"I am updating value2 to 4".
Hazelcast如何处理呢?
How does Hazelcast handle this?
最终结果将如下所示吗?
Will the final result look like the following?
key: {value1: 3, value2: 4}
推荐答案
Hazelcast使用分区.密钥被散列以找到该条目的正确分区.
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.
我不太了解您的表示法:key: {value1: 1, value2: 2}
->它看起来像一个嵌套的地图.
I don't really understand your notation: key: {value1: 1, value2: 2}
-> it looks like a nested map.
您也说:the same key but different values of that key.
->在映射中,每个键只有一个值(除非该值是集合或映射)
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)
这篇关于Hazelcast IMap-并发更新到相同的键,但值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!