Re: Java Runtime.exec problem
On Jul 16, 10:29 am, Steven Simpson <s...@domain.invalid> wrote:
suru wrote:
i tried with Thread.join approach,
for some calls it just hangs after join call :(
Where did you put the join()s? Which one is hanging? Can you determ=
ine
whether the gobblers have completed? What does your code look like
now? (Take note of others' comments about SSCCEs too.)
From your original post:
outputProcess.waitFor();
toolkitOutput = toolkitOutput + outputGobbler=
..getOutput();
toolkitOutput = toolkitOutput + errorGobbler.=
getOutput();
I think you're going to have to do some sort of waiting (e.g. join())
between waitFor() and getOutput() anyway, as you need to make sure that
your gobblers have finished by then. You could make getOutput() block
until the stream is finished, instead of using join().
Get the gobblers (instead of anything else) to close the streams too.
There's no reason for anything else to be dealing with the streams (is
there?).
Also you might consider using an Executor and/or a Future
(FutureTask).
Thread coordination is a fairly advanced topic. After decades of
working with concurrent programming, I still keep researching,
studying and repeating that research and study, and I still feel that
I need to keep doing so.
I recommend the book /Java Concurrency in Practice/ by Brian Goetz, et
al. There are articles by Mr. Goetz available on the IBM
DeveloperWorks site that will help a lot. The Sun tutorials are a
decent starting point.
--
Lew