Marcus Leon
Marcus Leon

Reputation: 56679

Execute native code via JNI/DLL or EXE?

We have a native app that we can access via JNI->DLL or by invoking an EXE with command line parameters. Which would be the best approach?

We will be invoking this method about 100 times a day. Performance isn't super important. This native app was developed by a group outside of our company so we are not too familiar with the code (though we do own it).

The EXE route seems easier and more straightforward (especially as we haven't used a lot of C). Also I gather with JNI you can crash your JVM if if your DLL code has a memory leak or encounters some other troubles.

Upvotes: 3

Views: 2440

Answers (2)

Brian Agnew
Brian Agnew

Reputation: 272297

I would strongly recommend the .exe approach.

  1. if it crashes you can respawn the .exe
  2. you won't suffer from memory leaks / corruptions etc.

The downside is that you may have to parse the .exe output to determine results/status etc., and if it's not designed for this, then this might be impractical (or impossible, even).

But as a first approach, spawning the .exe is the way to go. Don't forget to consume the stdout/err concurrently to avoid any .exe hanging problems (a common problem, if SO questions are to be believed).

Upvotes: 6

Joachim Sauer
Joachim Sauer

Reputation: 308041

For this case I'd call the .exe, mostly because an unstable app in this case can't break the JVM.

And calling an .exe 100 times a day is easily fast enough.

On the other hand, if the .dll provides a good API, then using that might give you a better chance at diagnosing the problem should something go wrong.

Upvotes: 4

Related Questions