I am starting command line applications from Java. The problem is that starting application from a command line takes much less time than from Java. I heave read various StackOverflow questions similar to mine (for example, this one, other). They complain on the overhead inherent to Java and suggest various approaches to reduce startup overhead. Unfortunately, they do not report back whether they have really reached an improvement.
I have tried several approaches without success. I would like to hear what I am doing wrong. I will not provide slow code for ProcessBuilder.
NuProcessBuilder pb = new NuProcessBuilder(params);
pb.setCwd(Paths.get(inputFilePath));
ProcessHandler handler = new ProcessHandler();
pb.setProcessListener(handler);
NuProcess process = pb.start();
process.waitFor(1, TimeUnit.MINUTES);
Zt-Exec library (uses ProcessBuilder internally):
String output =
new ProcessExecutor()
.command(params)
.readOutput(true)
.timeout(1, TimeUnit.MINUTES)
.exitValue(0)
.directory(new File(inputFilePath))
.execute()
.outputUTF8();
I did not try this native lib since I saw the question that reported no improvement.
I reach only 2.476 seconds instead of only 869 ms running from command line. This is very critical for my application. These numbers are for Windows 10. I have carried out tests on Linux Ubuntu and got approx. the same ratio.
Any suggestions?