Why is DefaultExecutor creating 2 threads for calling the command "php file.php"
I'm using DefaultExecutor of apache-commons-exec to execute a php but when I see the profile I see that the the last line, the execute function is creating 2 parallel threads for call the process synchronous. Why?
CommandLine command = new CommandLine("php");
command.addArgument("file.php");
DefaultExecutor exec = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(null, null);
exec.setStreamHandler(streamHandler);
int execute = exec.execute(command);
The problem is that I call N threads with a loop calling the exec.execute(command);, so if I use 3 threads, every time the execute is being called the APP is creating 6 new threads that dies when the exe开发者_StackOverflow中文版c.execute(command); finishes.
http://i.imgur.com/ap5mo.jpg
i'm not familiar with the library in question, but generally in java when you are executing a separate process, you need extra threads to correctly handle the standard output/error (otherwise the process may block). i would guess those are the extra threads you are seeing (details on handling process execing here).
精彩评论