简体   繁体   English

如何在两个独立的应用程序中使用一个 Java 对象?

[英]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.例如,如果超过 5 分钟没有数据存储在数据库中,则发送电子邮件。

How can I accomplish that ?我怎样才能做到这一点? I don't know how to use the same Java Object with two different applications.我不知道如何在两个不同的应用程序中使用相同的 Java 对象。 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. Java 不支持在两个实例之间共享同一个对象。 There are however many ways to share state between objects.然而,有很多方法可以在对象之间共享状态。

One solution is Hazelcast and certainly does the trick.一种解决方案是 Hazelcast,当然可以解决问题。 It also works when jvm instances are on different machines.当 jvm 实例位于不同的机器上时,它也可以工作。

When the jvm's are on the same machine you could (de)serialize your object in shared memory.当 jvm 位于同一台机器上时,您可以(反)序列化共享内存中的对象。 This is described here: Shared Memory between two JVMs此处描述: 共享内存在两个 JVM 之间

However, I would most likely advise you to use hazelcast because it is simple.但是,我很可能会建议您使用hazelcast,因为它很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何同步两个java应用程序? - How can I synchronize two java applications? 使用一个spring安全性保护两个单独的Java应用程序 - Secure two separate java applications with one spring security 如何使用批处理文件运行两个Java应用程序? - How can i run two java applications using a batch file? 访问MySQL数据库时如何同步两个单独的Java应用程序 - How to synchronize two separate Java Applications when accessing a MySQL database 我如何使用java来捕获某些应用程序的屏幕? - How can I use java to capture the screen of some applications? 如何在Java中将任意字符与字符串对象分开 - How can I separate the arbitrary characters from a string object in java 如何在 java 中将一个字符串分隔为多个 json object? - how can i Separate a string to many json object in java? 两个独立的 Java 桌面应用程序之间的通信 - Communication between two separate Java desktop applications 我如何使用Java,RestAssured测试Web服务自动替换Json目标文件中的两个单独的ID - How can i automatically replace two separate ID's in Json object file using java, RestAssured testing web services 如何将ImageJ用作单独Java应用程序的库? - How can I use ImageJ as a library for a separate Java application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM