Disadvantages of using Java Native Interface

前端 未结 6 1141
南旧
南旧 2020-12-29 13:46

I can not get these two disadvantages of using JNI. I want to know more about them:

  • Difficult to debug runtime error in native code

  • Errors i

6条回答
  •  没有蜡笔的小新
    2020-12-29 14:24

    I'm not sure if this helps, but I used a native method to set a static flag in my JNI/C code to turn debug tracing on or off (default is off). Then I used good old printf() calls at the start of each JNI function that only executed if the flag was set. It's crude but it works.

    It's also a good idea to provide some kind of version checking between the Java class and its JNI functions. This can be done with a JNI function that gets called from a static class initializer block. If the client has the wrong combination of libraries (i.e., the jarfile got updated but the JNI shared library didn't, or vice versa), you can throw an exception at class load time.

提交回复
热议问题