Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 671
Marcus Leon Avatar asked Dec 17 '25 15:12

Marcus Leon


1 Answers

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).

like image 89
Brian Agnew Avatar answered Dec 19 '25 05:12

Brian Agnew