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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -