• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java interprocess communication

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just starting up the child process, and then using sockets for communication would probably be less brittle.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic