Topic
  • 8 replies
  • Latest Post - ‏2013-01-05T10:24:57Z by SystemAdmin
SystemAdmin
SystemAdmin
1245 Posts

Pinned topic JavaOp with JNI causes the exception that the native library already loaded

‏2013-01-02T03:20:31Z |
I have a JavaOp which has some native methods and System.loadLibrary() is put in its static constructor block. The streams application with two instances of this JavaOp will get crashed on startup due to Java exception which indicates that the same native library has been loaded. Does anyone have any ideas to solve the issue?

Best Regards,
Mike
  • hnasgaard
    hnasgaard
    200 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-02T13:03:49Z  
    Are those two java operators fused into the same PE? If so, try removing the fusion.
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-02T14:34:34Z  
    • hnasgaard
    • ‏2013-01-02T13:03:49Z
    Are those two java operators fused into the same PE? If so, try removing the fusion.
    No. no fusion.
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-03T01:47:55Z  
    No. no fusion.
    To make it more clear, the issue happened in the standalone mode.
  • hnasgaard
    hnasgaard
    200 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-03T12:02:30Z  
    To make it more clear, the issue happened in the standalone mode.
    In standalone mode every operator is fused into one PE. That probably explains why it gets an exception when the second load occurs. I'm still waiting to hear from our Java expert. Does it work correctly in distributed mode?
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-04T11:31:34Z  
    • hnasgaard
    • ‏2013-01-03T12:02:30Z
    In standalone mode every operator is fused into one PE. That probably explains why it gets an exception when the second load occurs. I'm still waiting to hear from our Java expert. Does it work correctly in distributed mode?
    Just thinking... If one PE, then the static constructor should be called only once. It looks that it is called several times. Actually it comes to the same issue that the resource sharing among java operators in one PE.
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-04T22:09:14Z  
    Just thinking... If one PE, then the static constructor should be called only once. It looks that it is called several times. Actually it comes to the same issue that the resource sharing among java operators in one PE.
    Can you share the stack trace and which JVM you are using.

    The javadoc for Runtime.loadLibrary() states:

    "If this method is called more than once with the same library name, the second and subsequent calls are ignored. "

    so it seems strange the an error is raised.
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-04T22:24:44Z  
    Can you share the stack trace and which JVM you are using.

    The javadoc for Runtime.loadLibrary() states:

    "If this method is called more than once with the same library name, the second and subsequent calls are ignored. "

    so it seems strange the an error is raised.
    Seems you are hitting the issue described here:

    http://stackoverflow.com/questions/1139386/check-if-a-dll-library-is-already-loaded-java

    So more likely the issue is the subsequent class loaders (one per operator) cannot use the shared library,
    which is described as intentional for Java in this bug report.

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4642062
  • SystemAdmin
    SystemAdmin
    1245 Posts

    Re: JavaOp with JNI causes the exception that the native library already loaded

    ‏2013-01-05T10:24:57Z  
    Seems you are hitting the issue described here:

    http://stackoverflow.com/questions/1139386/check-if-a-dll-library-is-already-loaded-java

    So more likely the issue is the subsequent class loaders (one per operator) cannot use the shared library,
    which is described as intentional for Java in this bug report.

    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4642062
    I am using IBM JDK instead of Sun's. The version is v6.0.