Ian Renton
Ian Renton

Reputation: 729

Is there a standard way of synchronising a Map of objects across a network?

In Java, I have a HashMap containing objects (which can be serializable, if it helps). Elsewhere on a network, I have another HashMap in another copy of the application that I would like to stay in sync with the first.

For example if on computer A, someone runs myMap.put("Hello", "World"); and on computer B, someone runs myMap.put("foo", "bar");, then after some time delay for changes to propagate, both computers would have mayMap.get("Hello") == "World" and mayMap.get("foo") == "bar".

Is this requirement met by an existing facility in the Java language, a library, or some other program? If this is already a "solved problem" it would be great not to have to write my own code for this.

If there are multiple ways of achieving this I would prefer, in priority order:

  1. Changes are guaranteed to propagate 100% of the time (doesn't matter how long it takes)
  2. Changes propagate rapidly
  3. Changes propagate with minimal bandwidth use between computers.

(Note: I have had trouble searching for solutions as results are dominated by questions about synchronizing access to a Map from multiple threads in the same application. This is not what my question is about.)

Upvotes: 1

Views: 170

Answers (2)

Nirav Prajapati
Nirav Prajapati

Reputation: 3005

what you are trying to do is call clustering between two node

here i have some solution

  1. you can achieve your requirement using serialization make your map serializable read and write state of map in each interval of time and sync it.this is core and basic way to achieve your functionality.but by using serialization you have to manually manage sync of map(i.e you have to do code for that)

  2. Hazelcast open source distributed caching mechanism hazelcast is best api and have reach libarary to achive cluster environment and share data between different node

  3. coherence web also provide mechanism to achieve clustering by Oracle

  4. Ehcache is a cache library introduced in 2003 to improve performance by reducing the load on underlying resources. Ehcache is not for both general-purpose caching and caching Hibernate (second-level cache), data access objects, security credentials, and web pages. It can also be used for SOAP and RESTful server caching, application persistence, and distributed caching

among all of above Hazelcast is best api go through it will sure help you

Upvotes: 1

vikingsteve
vikingsteve

Reputation: 40418

You could look at the hazelcast in-memory database.

It's an open source solution designed for distributed architectures.

It maps really well to your problem since the hazelcast IMap extends java.util.Map.

Link: Hazelcast IMap

Upvotes: 3

Related Questions