I have 2 separate Java Applications running at a time. (Two separate javaw.exe) I need to share an object between them while they are running.
What is the simplest
I think that Hazelcast works fine for this type of situation. It practically requires no setup (more than that you need to add the dependencies to the Hazelcast jars). The following code sample shows how to setup a shared Map
.
// Code in process 1
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
Map sharedData = instance.getMap("shared");
sharedData.put(1, "This is shared data");
// Code in process 2
Config cfg = new Config();
HazelcastInstance instance = Hazelcast.newHazelcastInstance(cfg);
Map sharedData = instance.getMap("shared");
String theSharedString = sharedData.get(1);
Hazelcast support various shared data structures including Map
, Queue
, List
, AtomicLong
, IdGenerator
etc. The documentation is good and in my experience the implementation is solid.