本文介绍了本地JVM之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题:我可以/应该采取什么方法在本地运行的两个或多个JVM实例之间进行通信?

My question: What approach could/should I take to communicate between two or more JVM instances that are running locally?

问题的一些描述:

我正在为一个项目开发一个系统,该系统需要单独的JVM实例来完全隔离某些任务。

Some description of the problem:
I am developing a system for a project that requires separate JVM instances to isolate certain tasks from each other entirely.

在它运行时,'父'JVM将创建它将期望执行的'子'JVM,然后将结果返回给它(以相对简单的POJO类或结构化XML数据的格式)。不应使用SysErr / SysOut / SysIn管道传输这些结果,因为孩子可能已经将这些结果用作其运行的一部分。

In it's running, the 'parent' JVM will create 'child' JVMs that it will expect to execute and then return results to it (in the format of relatively simple POJO classes, or perhaps structured XML data). These results should not be transferred using the SysErr/SysOut/SysIn pipes as the child may already use these as part of its running.

如果子JVM没有响应结果在一定时间内,父JVM应该能够向孩子发出信号停止处理,或者杀死子进程。否则,子JVM应该在完成任务时正常退出。

If a child JVM does not respond with results within a certain time, the parent JVM should be able to signal to the child to cease processing, or to kill the child process. Otherwise, the child JVM should exit normally at the end of completing its task.

到目前为止的研究:

I我知道有许多可能有用的技术,例如......

Research so far:
I am aware there are a number of technologies that may be of use e.g....


  • 使用Java的RMI库

  • 使用套接字传输对象

  • 使用分发库,如Cajo,Hessian

...但我有兴趣听取其他人在寻求其中一种选择之前可能会考虑的方法,或者其他任何选择。

...but am interested in hearing what approaches others may consider before pursuing one of these options, or any others.

感谢您对此提出任何帮助或建议!

Thanks for any help or advice on this!

编辑:

要转移的数据量 - 相对较小,主要是只有少数POJO包含代表子执行结果的字符串。如果任何解决方案在大量信息上效率低下,那么不太可能成为我系统中的问题。传输的数量应该是非常静态的,因此必须是可扩展的。

Edits:
Quantity of data to transfer- relatively small, it will mostly be just a handful of POJOs containing strings that will represent the result of the child executing. If any solution would be inefficient on larger amounts of information, this is unlikely to be a problem in my system. The amount being transferred should be pretty static and so this does not have to be scalable.

转移的延迟 - 在这种情况下不是一个关键问题,尽管如果需要对结果进行任何轮询,这应该是相当频繁而没有显着的开销,所以我可以在以后维护一个响应式GUI(例如进度条)

Latency of transfer- not a critical concern in this case, although if any 'polling' of results is needed this should be able to be fairly frequent without significant overheads, so I can maintain a responsive GUI on top of this at a later time (e.g. progress bar)

推荐答案

我将与本地套接字一起使用,因为它专门用于序列化并且非常轻量级(你也得到远程方法调用!我现在正在使用它),但是禁用套接字断开超时。

I'd use KryoNet with local sockets since it specialises heavily in serialisation and is quite lightweight (you also get Remote Method Invocation! I'm using it right now), but disable the socket disconnection timeout.

RMI基本上工作原理是你有一个远程类型并且远程类型实现了一个接口。此接口是共享的。在本地计算机上,通过RMI库将接口绑定到RMI库中的inject内存代码,结果是您拥有满足接口但能够与远程对象通信的内容。

RMI basically works on the principle that you have a remote type and that the remote type implements an interface. This interface is shared. On your local machine, you bind the interface via the RMI library to code 'injected' in-memory from the RMI library, the result being that you have something that satisfies the interface but is able to communicate with the remote object.

这篇关于本地JVM之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 05:51
查看更多