简体   繁体   中英

How can I use one Java Object in two separate applications?

I have an application that create a statistics Object and update it through the execution. The datas stored in that object are for example the date the application encountered the last disconnection, the number of message stored in the DB, etc...

I would like another app that is capable of for example triggering some alert if some of the datas exceed a certain value. Such as sending an email if there is no data stored in the DB for more than 5 minutes.

How can I accomplish that ? I don't know how to use the same Java Object with two different applications. What are the different methods to do that and what is the best option ?

Java does not support sharing the same object between two instances. There are however many ways to share state between objects.

One solution is Hazelcast and certainly does the trick. It also works when jvm instances are on different machines.

When the jvm's are on the same machine you could (de)serialize your object in shared memory. This is described here: Shared Memory between two JVMs

However, I would most likely advise you to use hazelcast because it is simple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM