How to integrate an external process that is repeatedly called in Java Webapp?

I am trying to integrate a non-Java executable into a Java serverapp (server side) (Linux).

Some information about the executable file:
Written in C ++. The executable takes some input from either stdin or the file and generates an output file. The executable file is not designed for a long process, that is, it generates output and then dies out.

When you start a separate process for an executable file, it’s quite inexpensive, the number of calls made in it can be high. This can lead to too many processes that can degrade server performance.

How can I write some shell or utility (in Java) around this exe so that I can work effectively as

  • stream from my java application
  • long external process

PS: I know that I can start an external process using Runtime or ProcessBuilder in Java and possibly make it multithreaded and use some sequence, but this does not solve the problem of starting the process over and over again.

+3
source share
4 answers

If you:

a) You can change the source code.

I would recommend that you create a lengthy process and expose it as a web service. That way, the process will only sit there, waiting for a call.

b) Have the source code / headers, but you cannot change it.

, java JNI, JNA, .

C) .

, .

+1

++ , ++, .

, ++ API JNI JNA API Java. JNI/JNA JVM. - (, JVM), .

++ . "" , , :

while (true) {
    read request from a socket / pipe
    process request
    write answer to socket / pipe
}

, Java Webapp ++ Runtime.exec(...), . (IPC ), ++ , .

, , - . - (, webapp), -, , Java, ++. , Java, . .

+1

How many processes are too many? I suggest measuring performance before moving on. Perhaps you can start and run many more processes without problems than you expect, especially since the program code will be shared in memory in all instances.

0
source

Source: https://habr.com/ru/post/1721844/


All Articles