Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java interprocess communication

 
krats ram
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just starting up the child process, and then using sockets for communication would probably be less brittle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic