• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic