wood burning stoves
The moose likes Java in General and the fly likes Java interprocess communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java interprocess communication" Watch "Java interprocess communication" New topic

Java interprocess communication

krats ram

Joined: Oct 11, 2009
Posts: 9
I am trying to write some code for twp java programs to communicate. Below are the two programs

and the other program

When I run the caller, the two programs run for a while with output

Whats up Caller !
... Whats up Caller ! got your msg

and then they block. Any suggestions?
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

You should read and implement this article: When Runtime.exec() won't by Michael Daconta. The vast majority of problems found with Runtime.exec() and Processes in general are addressed their (the fact that he uses Runtime.exec() and you use ProcessBuilder is only significant in that the article was written long ago - everything still applies).

My guess is that your Callee's output buffer is filling. You send 1 line from the caller, the callee sends 2 lines back, and the caller consumers just 1 leaving the other line in the buffer waiting to be consumed. Eventually the buffer fills because you add to it twice as fast as you consume from it.

The article gives a nice class for consuming and reporting all the output from the Process.

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
Just starting up the child process, and then using sockets for communication would probably be less brittle.
I agree. Here's the link: http://aspose.com/file-tools
subject: Java interprocess communication
It's not a secret anymore!