java中IPC的最佳方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21025017/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 06:02:39  来源:igfitidea点击:

What is the best way for IPC in java?

java

提问by Sivam

I am using Netbeans for developing two separate application.

我正在使用 Netbeans 开发两个单独的应用程序。

I need to communicate between two jar what is the best IPC Communication.

我需要在两个 jar 之间进行通信,什么是最好的 IPC 通信。

采纳答案by Philipp

There is never a bestway to solve a problem. There is only the way which works best for you.

从来没有解决问题的最佳方法。只有最适合您的方法

When you have two separate processes running on different hosts, you need to communicate via network sockets. You could use an existing protocol standard like SOAP. When you are sure that none of the two applications will ever be rewritten in a different programming language, you could also use ObjectOutputStream and ObjectInputStreamconnected to network sockets and exchange Java objects directly between the two programs. Or you could design your own protocol from scratch which is optimized for your application.

当您在不同的主机上运行两个独立的进程时,您需要通过网络套接字进行通信。您可以使用现有的协议标准,如SOAP。当您确定这两个应用程序都不会用不同的编程语言重写时,您还可以使用连接到网络套接字的ObjectOutputStream 和 ObjectInputStream并直接在两个程序之间交换 Java 对象。或者,您可以从头开始设计自己的协议,该协议针对您的应用程序进行了优化。

When the processes run on the same host, communicating via network is often still a good option. But there are others like communicating via writing and reading temporary files. You could also go the UNIX way, and have one application write to System.outand pipe its output to the other program which reads it with System.in.

当进程在同一台主机上运行时,通过网络进行通信通常仍然是一个不错的选择。但是还有其他一些喜欢通过写入和读取临时文件进行通信。您也可以采用 UNIX 方式,让一个应用程序写入System.out并将其输出通过管道传输到另一个使用System.in.