Hi all,
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 way to achieve this without having any permanent storage?
Hi all,
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 way to achieve this without having any permanent storage?
Perhaps Oracle Coherence? That works like an in memory map shared across applications.
You can use TCP
Example: http://www.java-samples.com/showtutorial.php?tutorialid=1167
If you can't store the object permanently, you need to transfer it somehow. This can be done either via network or some sort of shared memory.
For first (network) approach, use serialization (java.io.Serializable) and transfer the object over socket. This will require writing socket listeners.
Second approach will require using and configuring a third party library (e.g. EHCache).
Objects and their instance variables can be shared between threads in a Java program, which is pretty simple task.
If you require to share objects (instance of it) between two programs, with out data storage, next choise would be using RMI Socket Communication or Java messaging service.
You must decide if you prefer shared and updated state, or simply send an one-time-message-object.
In the first case you would have to share a "remote reference" to some object. RMI is a good approach.
In the second case you only need to serialize the object you want to share and send it. You can send it serialized (converted to byes) over a socket as Ankit said or even you can use:
RMI :) The sender connects to a RMI registered receiver, invokes a method with the mesasge object as a param and forgets about the RMI object
Java Messaging Service (JMS), maybe an overkill...
some other creative but simple thing...