Dead Programmer
Dead Programmer

Reputation: 12585

Sharing Data between 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
--------------                                                  -------------------

Upvotes: 7

Views: 3098

Answers (1)

Vivien Barousse
Vivien Barousse

Reputation: 20895

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).

Upvotes: 11

Related Questions