Reputation: 729
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:
(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
Reputation: 3005
what you are trying to do is call clustering between two node
here i have some solution
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)
Hazelcast open source distributed caching mechanism hazelcast is best api and have reach libarary to achive cluster environment and share data between different node
coherence web also provide mechanism to achieve clustering by Oracle
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
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