I understand the following is the typical code to launch an exe from java
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("some.exe");
or with parameter
Process process = new ProcessBuilder("some.exe","param1","param2").start();
I have a web application which wraps an exe and users can execute these on request. As I understand the above two approaches will always create a new process on every request. I want to avoid this.
Is there way, wherein I keep a pool of reusable loaded instances and use them in the typical concurrent scenario. I want avoid a situation wherein each user request launches a new process.
That depends on whether
some.exesupports this. For example, the commandls(ordir) does its thing and stops. There is no way to tell it “do it again” – you need a way to communicate with the process and the process must have some interface (usually stdio) which you can use to remote control it.If your external process can’t do it, then you must create a new process per request or you must run the process somewhere else and keep the results in a cache for some time, so several user requests get the same data without you having to run the process.
So if you get 100 requests per user and minute and it’s okay for the data to be one minute old, then you could run the process once per minute and reuse the old results.