在java中IPC最好的方法是什么? [英] What is the best way for IPC in java?

查看:106
本文介绍了在java中IPC最好的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using Netbeans for developing two separate application.

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

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

推荐答案

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

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

当你在不同的主机上运行两个独立的进程时,你需要通过< a href =http://docs.oracle.com/javase/tutorial/networking/sockets/ =noreferrer>网络套接字。您可以使用现有的协议标准,如 SOAP 。如果您确定这两个应用程序都不会用其他编程语言重写,您也可以使用 ObjectOutputStream和ObjectInputStream 连接到网络套接字并直接在两个程序之间交换Java对象。或者您可以从头开始设计自己的协议,该协议针对您的应用进行了优化。

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 ObjectInputStream connected 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.

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

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.out and pipe its output to the other program which reads it with System.in.

这篇关于在java中IPC最好的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆