开发者

Sharing Data between JVM

开发者 https://www.devze.com 2023-01-17 04:16 出处:网络
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 ha

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
-------------开发者_Go百科                                                   -----------------
jvm 1                  PASS THE DATA TO ANOTHER THREAD IN A         JVM2  

                         NOTHER JVM
                         ===============>>>>>  
tHREAD T1                                                          tHREAD T2
--------------                                                  -------------------


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

精彩评论

暂无评论...
验证码 换一张
取 消