multithreading - Thread-launched running processes won't destroy (Java) -
starting multiple threads , having each exec() destroy() running java process result in of process not being destroyed , still running after program exit. here code reproduce issue. noticed more threads start, more processes stay alive. , more sleep before destroy(), less processes stay alive. (i used infiniteloop example. running process trick.)
edit : bug has been reported oracle, waiting answer. feel free share knowledge/experiments on subject.
for(int = 0; < 100; i++) { new thread(new runnable() { public void run() { try { process p = runtime.getruntime().exec(new string[]{"java", "infiniteloop"}); thread.sleep(1); p.destroy(); }catch(ioexception | interruptedexception e){e.printstacktrace();} } }).start(); }
if subprocesses write stdout or stderr (intentionally or not), cause trouble:
"because native platforms provide limited buffer size standard input , output streams, failure promptly write input stream or read output stream of subprocess may cause subprocess block, , deadlock."
source: http://www.javaworld.com/jw-12-2000/jw-1229-traps.html
the whole article imo worth reading if need use runtime.exec().
Comments
Post a Comment