开发者

JNA Library Reload Under Win32 Hangs

I'm having an interesting JNA issue here.

Under JRE 1.6 and 1.7 x64, I can load and unload a library, like such:

this.Lib = (LibHandler)Native.loadLibrary(this.Name, LibHandler.class);
this.Lib.Initialize();
this.Lib = null;
Ru开发者_开发技巧ntime.getRuntime().gc();
this.Lib = (LibHandler)Native.loadLibrary(this.Name, LibHandler.class);
this.Lib.Initialize();

This will load it, run the initialization routine, set the class to null and force the GC to clean it up which will unload the library (to my misunderstanding, if I'm doing this wrong please correct me!), and reload and reinitialize it. Runs perfect on x64.

However on x86, this code will fail to load the second Initialize() (which in this example, really just returns on the C library), it will just hang there doing nothing, I can do everything else with these libraries except reload them.

Am I missing something or did I stumble onto something that needs to be reported to the JNA dev team?

Edit:

I do have a way of handling this (basically restarting the java application on library swap, which isn't a big deal), but I still want to know if this is a bug or not.

Edit 2:

Wrote a test case in case I had to submit this:

public class EntryPoint {
    public static void main(String[] args) {
        String path = new File("").getAbsolutePath();
        System.out.println("Path: " + path);
        
        ITest it = (ITest)Native.loadLibrary(path + "\\jnaFailureC_x86.dll", ITest.class);
        System.out.println("Expecting 'Test', result: '" + it.myMethod().getString(0) + "'");
        
        WeakReference<ITest> itRef = new WeakReference<ITest>(it);
        it = null;
        Runtime.getRuntime().gc();
        if(itRef.get() != null){
            System.out.println("Not collected.");
        }else{
            System.out.println("Collected");
        }

        it = (ITest)Native.loadLibrary(path + "\\jnaFailureC_x86.dll", ITest.class);
        System.out.println("Expecting 'Test', result: '" + it.myMethod().getString(0) + "'");
        
        
    }
}

Path: G:\Source\jnaFailure
Expecting 'Test', result: 'Test'
Collected
Expecting 'Test', result: 'Test'

Works fine, bleh, I'm assuming maybe something else was referencing it on my production code and it wasn't actually releasing it, always check weak references!


This seems to be a bug, I haven't found a solution other than just restarting the service. It's probably best to restart on a library update anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜