Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing Data between JVM

Tags:

java

jvm

Today i was asked this question about sharing data from a thread t1 that runs in one jvm 1 to a thread 2 running in another jvm 2, and similarly to another thread t3 in jvm 3. after some homework i had told the following answer.kindly let me know if you have better and efficient answer.

  1. SERIALIZATION
  2. java nio Stream
-------------                                                   -----------------
jvm 1                  PASS THE DATA TO ANOTHER THREAD IN A         JVM2  

                         NOTHER JVM
                         ===============>>>>>  
tHREAD T1                                                          tHREAD T2
--------------                                                  -------------------
like image 610
Dead Programmer Avatar asked Sep 18 '10 19:09

Dead Programmer


People also ask

How data sharing among classes is achieved in Java?

When the JRE is installed using the installer, the installer loads a set of classes from the system jar file into a private internal representation, and dumps that representation to a file, called a "shared archive". If the JRE installer is not being used, this can be done manually, as explained below.

Can two JVM run on same machine?

Yes, you can run multiple JVM's on a single machine.

What is shared memory in Java?

A shared memory connection allows both the client and the database to share the same memory on their host machine. This shared memory is temporary, and it is backed up by virtual memory. Shared memory connections are automatically used by Java applications running on the same machine as an InterSystems IRIS instance.


1 Answers

I think it depends on the context of your application. You have multiple options:

  • Serialization can work, but is very likely to break if your code changes. This can lead to data loss.
  • To share data between multiple applications, you can use a database. That's one of the best option in my mind, since your data will be structured.
  • Also, you can use a formatted text file. Just choose how to format your data, put that in a file, and then read the file from another application.
  • If your JVM are on different computers, you can try using sockets. This way, your applications will be able to communicates via the network.
  • If you can have a server acting like a relay for your objects, you can also use a messaging server (I'm thinking about JMS).
like image 64
Vivien Barousse Avatar answered Sep 19 '22 01:09

Vivien Barousse