Hazelcast IMap

系统教程 行业动态 更新时间:2024-06-14 16:57:18
Hazelcast IMap - 同时更新相同的密钥,不同的价值(Hazelcast IMap - Concurrent updates to the same key, different value)

没有测试,因为我被困在火车上并且没电了......

我需要确定Hazelcast的IMap并发更新是否是线程安全的,更新相同的密钥但该密钥的值不同。

例如:

假设我有2个不同的线程更新相同的IMap密钥......

出于所有意图和目的,此映射如下所示:

key: {value1: 1, value2: 2}

一个帖子说,

"I am updating value1 to 3"

另一个帖子说(同时)

"I am updating value2 to 4".

Hazelcast如何处理这个问题?

最终结果是否如下所示?

key: {value1: 3, value2: 4}

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}

最满意答案

Hazelcast使用分区。 密钥被散列以找到该条目的正确分区。

每个分区都是单线程的,每个分区只有一个分区线程处理。 因此,单个密钥由单个分区线程处理。

如果两个更新的密钥都位于同一分区中,则这些操作将在单个分区线程上顺序执行。 如果每个密钥都位于不同的分区中 - 不同的线程将处理每个更新。

我真的不明白你的符号: key: {value1: 1, value2: 2} - >它看起来像一个嵌套的地图。

你也说: the same key but different values of that key. - >在地图中,每个键只有一个值(除非该值是集合或地图)

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)

更多推荐

本文发布于:2023-04-12 20:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/173958b6bf749512d6db74d0d48df7e2.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Hazelcast   IMap

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!