I need to execute a python script with arguments passed from my user interface and display the results. I know how to do this using ProcessBuilder (below) but I presume that just calling this code from the relevant Spring @Service isn't a good idea (threading issues, too many instances running concurrently, etc). What would be the best approach?
@Override
public String executeLatestAlgorithm(String json) {
try {
ProcessBuilder probuilder = new ProcessBuilder("somescript.py", json);
Process p = probuilder.start();
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
return in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
(crap code without any significant errorhandling - just to illustrate)
Many thanks,
A