What are the bottlenecks to using the suggested methods?
The biggest problem with this is your hardware and the executable itself. If the executable completes by itself after some time, you should be fine. You don't want 1000's of processes waiting for something to complete. You need to also monitor the processes once they started and kill them if they reach a timeout. Another consideration is limiting the number of concurrent processes per user.
For example, if a user clicks on the button and runs the executable, would this affect the performance for the second user?
Not directly. See above.
Or if they press the button at the same time, what is going to happen?
If you start your process on a new thread (or task scheduler) each time, nothing. each time the button is pressed a new process is started.
Or how would I know if the execution is completed(I don't think OS is going to manage for me).
Here is an example:
String command = "PATH_TO_EXECUTABLE/EXECUTABLE PARAMS ";
log.info("Executing command - " + command);
// Executing the command
Process process;
ArrayList<String> outLines = new ArrayList<String>();
try {
process = Runtime.getRuntime().exec(command);
// Getting the results
process.getOutputStream().close();
String line;
log.info("Standard Output:");
BufferedReader stdout = new BufferedReader(new InputStreamReader(
process.getInputStream()));
while ((line = stdout.readLine()) != null) {
log.info(line);
outLines.add(line);
}
stdout.close();
log.info("Standard Error:");
BufferedReader stderr = new BufferedReader(new InputStreamReader(
process.getErrorStream()));
while ((line = stderr.readLine()) != null) {
log.info(line);
}
stderr.close();
log.info("Done");
} catch (IOException e) {
log.error("Error while exceuting command", e);
}
String result = outLines.get(outLines.size()-1);
//TODO do something with the results
//at this point the process has finished executing