

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
11 messages in net.java.dev.jna.usersRE: [jna-users] NativeLibrary Usage| From | Sent On | Attachments |
|---|---|---|
| Christine Grudecki | Jul 26, 2007 7:11 am | |
| Timothy Wall | Jul 26, 2007 8:35 am | |
| Christine Grudecki | Jul 26, 2007 12:52 pm | |
| Timothy Wall | Jul 26, 2007 1:21 pm | |
| pzab...@poczta.onet.pl | Jul 27, 2007 8:57 am | |
| Timothy Wall | Jul 27, 2007 11:24 am | |
| Timothy Wall | Jul 30, 2007 3:41 am | |
| Timothy Wall | Jul 30, 2007 7:54 am | |
| Timothy Wall | Jul 30, 2007 8:58 am | |
| Christine Grudecki | Jul 30, 2007 9:24 am | |
| Timothy Wall | Jul 30, 2007 10:49 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | RE: [jna-users] NativeLibrary Usage | Actions... |
|---|---|---|
| From: | Christine Grudecki (Chri...@vayan.com) | |
| Date: | Jul 26, 2007 12:52:41 pm | |
| List: | net.java.dev.jna.users | |
That sounds like it would work, but I can't figure out how to implement it because MyLibrary is an Interface. I thought maybe implementing Library from an abstract class, but I can't figure out how to make that work with the way JNA works.
Can you give an example of how that would look?
Thanks!
-----Original Message----- From: Timothy Wall [mailto:twal...@dev.java.net] Sent: Thursday, July 26, 2007 10:36 AM To: use...@jna.dev.java.net Subject: Re: [jna-users] NativeLibrary Usage
On Jul 26, 2007, at 10:11 AM, Christine Grudecki wrote:
Currently, I'm opening and using the library as per the documentation. However, my server is crashing after a few iterations of my program because there is no way to close the library after opening it during each iteration (it runs on a scheduler every 10 minutes). I think I need to be using the NativeLibrary class since it has the Finalize method, but I can't find any documentation or examples of how to use it instead of the Library interface.
Can I use the Library interface in conjunction with the NativeLibrary class? Or are they mutually exclusive? How do I convert the example to use
Here are snippets of my code:
public interface MyLibrary extends Library {
MyLibrary INSTANCE = (MyLibrary) Native.loadLibrary("/usr/local/lib/MyLibrary.so", MyLibrary.class);
This pattern should only be used if you are *not* concerned about the library being closed and disposed. When you use the singleton INSTANCE pattern, the library will remain opened until the MyLibrary interface class object gets GC'd.
In order to enable GC of the library as soon as possible, use a local variable instead of a static instance to hold the result of Native.loadLibrary. You shouldn't need to use NativeLibrary directly; the InvocationHandler for your library interface instance will hold the only reference to the NativeLibrary (the NativeLibrary cache uses weak references), so when the library interface gets GC'd, the corresponding NativeLibrary will also be disposed.







