java double free or corruption

前端 未结 1 878
南旧
南旧 2021-01-12 00:06

maybe stupid question but i\'m getting randomly following error when running my *.jar package. Sometimes programm runs flawlessly and sometimes interrupts putting this out i

相关标签:
1条回答
  • 2021-01-12 00:53

    I know that this is an old thread but just in case someone fails in the same error.

    This is a multi-threading issue with a native library you are using.

    To cut the long story short, the java loads the native library into memory then it is accessed by multiple threads at the same time, then this error pops up.

    A quick workaround for this issue is to mark the method that generating this error as synchronized.


    Update after @kit comment.

    It is not possible to run such native library in multi-threading environment.

    Your options are:

    • modify the native library to make it thread-safe (if you have access to its code).
    • wrap it as an application and run multiple copies as separate processes (because native library is loaded once per process)
    • wrap it as a service and run multiple copies, talking to it using Sockets or an appropriate higher-level RPC mechanism.

    Credits: Load the same dynamic library in two threads (both threads in the same JVM)

    0 讨论(0)
提交回复
热议问题