I have a C++ a class that is using JNI Invocation mechanism to create a JVM and call methods in a java application. I am using IBM Java 1.4.2 version with the Visual Age C++ 9.0 compiler and running the application in Windows XP.
We had the JVM created using the main application thread at the very beginning when the application initializes. We also invoked the JNI method once at the application initialization so that it will load all the Java DLLs, needed Java classes to run the method into memory. When a button is clicked on the UI (from different threads) this JNI method gets invoked. Therefore we had to use attachcurrentthread prior to invoking the method and detachcurrentthread after invoking the method.
Everything worked fine.
But then we had to move the JVM creation/initial invocation of the JNI method to a different thread. This thread gets spawned by the main application thread and it will keep running till the application terminates. But now we are seeing an intermittent problem that sometime JVM is failing to get created (return with -1). Or sometimes the JVM gets created successfully but when the Java method get invokes it fails with link error or class not found error.
We have close to 2500 machines running with this code, but whenever the application starts up only about 30 machines fails with the error and it is occurring randomly.
Here is the error that Java is throwing for the cases where it is able to create the JVM but still unable to invoke the method.

Caused by: java.lang.UnsatisfiedLinkError: C:\Program Files\IBM\WebSphere\AppClient\java\jre\bin\nio.dll : The segment is already unlocked
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.jav a:2144)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java :2004)
at java.lang.Runtime.loadLibrary0(Runtime.java:824)
at java.lang.System.loadLibrary(System.java:910)
at sun.security.action.LoadLibraryAction.run(LoadLibr aryAction.java:76)
at java.security.AccessController.doPrivileged1(Nativ e Method)
at java.security.AccessController.doPrivileged(Access Controller.java:287)
at sun.nio.ch.Util.load(Util.java:280)
at sun.nio.ch.Net.<clinit>(Net.java:231)
at sun.nio.ch.WindowsSelectorImpl.<clinit>(WindowsSel ectorImpl.java:73)
at sun.nio.ch.WindowsSelectorProvider.openSelector(Wi ndowsSelectorProvider.java:52)

Has anyone ever seen a similar error. I googled and search lot of web sites but could not find anything related to this spefic problem.
So any help is greatly appreciated.