I am using Netbeans for developing two separate application.
I need to communicate between two jar what is the best IPC Communication.
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.
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.
Different ways of IPC are pipe, message passing, message queue, shared memory, direct communication, indirect communication and FIFO.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With