Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way for IPC in java? [closed]

Tags:

java

I am using Netbeans for developing two separate application.

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

like image 705
Sivam Avatar asked Jan 09 '14 15:01

Sivam


People also ask

How is the inter process communication done Java?

Inter-thread communication in Java is a mechanism in which a thread is paused running in its critical section and another thread is allowed to enter (or lock) in the same critical section to be executed. Note: Inter-thread communication is also known as Cooperation in Java.

What is a IPC in Java?

Inter-process communication (IPC) is a mechanism that allows processes to communicate with each other and synchronize their actions. The communication between these processes can be seen as a method of co-operation between them. Processes can communicate with each other through both: Shared Memory. Message passing.

What are the various IPC mechanisms?

Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.

How do you communicate between two JVMS?

One java app can run the other via Runtime. exec() and control it (communicate) using the input stream. One could use JNI and a OS specific feature like named pipes or shared memory. You can also use java RMI to communicate between two applications, one calling methods of the other.


1 Answers

There is never a best way 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 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.

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.

like image 168
Philipp Avatar answered Oct 22 '22 16:10

Philipp