Have a Map which contains objects that I want to keep in sync across multiple servers, such that if objects in the map are created, deleted, or modified – this is reflected immediately (ie. within a second or two) across all servers, in a way that can potentially scale up to tens of servers.
Is there a lightweight open source Java tool that can do something like this? I’m aware of Terracotta but it is rather heavy weight for what I need.
edit: The map is backed by a DB (specifically, Apache Cassandra) – but I need my clients to be informed of any changes to it within seconds, which would mean that I would need to poll Cassandra very frequently unless there is some other means to notify clients that the map has changed.
You can use Hazelcast.
If you are trying to share the same Map, Hazelcast will automatically do this for you.
Here is the code for this:
All JVM’s using “customers” map will see exactly the same data, even if it is updated frequently. If you also want to be notified whenever Map is changed then you can add listener. Here is how: