0

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 ?

Phoste
  • 1,141
  • 4
  • 18
  • 34
  • Possible duplicate of http://stackoverflow.com/questions/1680898/communication-between-two-separate-java-desktop-applications – Robin Topper Apr 13 '17 at 10:01
  • If those really are different applications, then what you're looking for is "interprocess I/O". There are a number of ways to do it, mainly via various APIs in `java.lang.Process`. Or, you know, just use a file to store stuff in. – M. Prokhorov Apr 13 '17 at 10:02
  • Your requirement does not mandate that you access the same object in two applications. Accessing the object's data is sufficient to achieve your goals. And there are tens of ways to remotely access some data (e.g. store it with a timestamp on a database, publish it on a message bus, access it via webservices, expose it as JMX, dump a file named with a timestamp, ... just for starters)... Would any of these suit you ? – GPI Apr 13 '17 at 10:24

1 Answers1

0

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.

Community
  • 1
  • 1
ipper
  • 624
  • 4
  • 13