Associating native calls with the calling object

I have a problem where calls into a native library need to retain data for subsequent method calls. Imagine the following two native methods (just imagine that the signature is write for JNI methods):
void initialise(int value)
// Stores the value somehow
void dosomething()
  // Does something with the previously stored value
}If I was to store the value in a global variable, then it would be shared across all instance of the java class wouldnt it? So if object 1 called initialise, then object 2 called initialise, whichever of the objects then called dosomething, it would be based on the latest call to initialise.
How do I get around this sort of thing?
I currently work in C, though I would be quite happy to switch to C++ if necessary.
Mossop

I haven't used JNI_OnUnload, but may see why it isn't called. The doc says it runs in the finalizer for the classloader that loaded the library. Assuming this is the system (not custom) classloader, then its finalizer will never run because it gets gc'd only at shutdown, and finalizers don't run at shutdown by default. You could try calling Runtime.runFinalizersOnExit, but it's deprecated and sounds unsafe.
So my next idea would be to add a shutdown hook (Runtime.addShutdownHook) the first time one of your objects is constructed. The hook would call a native method to do the cleanup. Or since a shutdown hook is a Thread subclass, just make your overridden run() be the native cleanup function.
Of course this now requires keeping a native-side data structure to track the native objects, though I'd still vote for storing each native peer's pointer in a Java long field for fast dereference, and make this native data structure be a simple array or list (not map) for usage only by the cleanup logic.
Another idea is to clean up in a function called by the OS or C++ runtime when your library is unloaded, independent of Java. This could be DllMain (for Windows) or a C++ global object destructor.
-slj-

Similar Messages

  • Does the ID associated with the BRF+ objects changes when transported?

    Hi Experts,
    Does the ID associated with the BRF+ objects(such as Catalogs, Data Objects, Expressions, Funcition) changes when transported to other environment?
    I just wonder if it is, because I am going to hardcode the ID of the Catalog I am calling using the FM WDY_EXECUTE_IN_PLACE.
    Thanks,
    Rob

    The ID is stable! That is exactly the idea of the ID, stable and unique accross systems.

  • How do I make a hands free call with the iphone 4s?

    How do I make a hands free call with the iphone 4s?  I have a bluetooth car device and when I try to talk through it (as I did with my old phone) to call someone it does not work.  so far only hte last person called is redialed.

    That is a carrier-based service. So first you have to make sure your service contract includes that feature.
    It usually also includes Call Hold. So you call the first party, put them on hold, call the second, then reactivate the first. But only if your carrier allows you to.

  • Portege R600 - Is it possible to make a call with the SIM?

    Hi,
    I wonder if its possible to use the Wireless connection manager 5 and to make or receive a call?

    Hi,
    I see that nobody answered so i will try to explain what i meant -
    Is it possible to make audio call with the Wireless Manager by the GSM modem module?
    I succeed to send SMS and to connect to HSPA data services but i dont find any reason why i can not connect to the GSM and make a call.
    I have Portege R600 model PPR61E-01C00NG3
    I even succeed to use the GPS that probably installed in the GSM/HSPA modem (wireless manager 5).
    If anyone can explain how and if it possible to make a call please send your reply ... i wnat to use the laptop with BT instead of cell phone ....
    Thanks
    Yan

  • Is it possible to run a subVI in parallel with the caller VI?

    I have a front panel VI which calls numerous subVIs, one or two of which I would like to execute simultaneously with the calling VI. The front panel has time-dependant operations which are being prevented from running because it is waiting for the subVIs to finish, even though no data is required from them.
    Is it possible to call these subVIs such that they run silently in the background allowing the front panel to execute unhindered?
    I've looked at the Synchronisation features but is this what I need?

    shoneill wrote:
    > It's also very important to mention that the whole multi-threaded
    > execution CANNOT be reliably observed in highlighting mode in the
    > LabVIEW development environment. You need to let the VI run
    > full-speed to see this.
    >
    > Highlighting (to the best of my knowledge) forces single-threading, or
    > acts like it does.
    This is simply a convinience by LabVIEW since humans are inherently
    non-multi treaded. What you will see in parallel loops and which can
    still be distracting is that LabVIEW seems to randomly switch between
    different parts of your diagram. In fact this is also what is happening
    in normal execution but the execution switch is so fast (each individual
    operation typically taking microseconds it
    seems they execute in parallel.
    The nice part of LabVIEW since version 2.0 somewhere around 1988 already
    is, that it provides this seemless multithreading on every single
    platform even if the underlaying OS is not multithreading capable at all
    (Win3.1, MacOS).
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Can i use DLL file created by Fortran with the call libary function node

    Can i use a DLL created by Fortran (Compaq Visual Fortran) with the call library function node in labview. If yes how do i create the DLL file if i have the Fortran code.
    Thanks

    Yes! Maybe these old post will help:
    http://forums.ni.com/ni/board/message?board.id=170&message.id=88786
    http://forums.ni.com/ni/board/message?board.id=170&message.id=109150
    Good luck!
    Message Edited by altenbach on 03-21-2006 02:35 PM
    LabVIEW Champion . Do more with less code and in less time .

  • I reset my phone and it now receives calls that were meant for my husband. I know how to fix this with messaging and facetime, but can't seem to find how to make it stop with the calls. Please help.

    I reset my phone and it now receives calls that were meant for my husband. I know how to fix this with messaging and facetime, but can't seem to find how to make it stop with the calls. Please help.

    It may be due to Continuity
    The following quote is from  Connect your iPhone, iPad, and iPod touch using Continuity
    Turn off iPhone cellular calls
    To turn off iPhone Cellular Calls on a device, go to Settings > FaceTime and turn off iPhone Cellular Calls.

  • I know the iphone 4s can turn off the vibrate for all sounds, but is there a way to keep the vibration on for just phone calls (with the ringtone also on) but off for everything else?

    I know the iphone 4s can turn off the vibrate for all sounds, but is there a way to keep the vibration on for just phone calls (with the ringtone) but off for everything else?

    Short answer: No.  Long answer: Nope
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf
    WYSIWYG   No hidden settings.
    If you want to suggest this to Apple:
    http://www.apple.com/feedback/iphone.html
    Message was edited by: modular747

  • When trying to answer a call with the phone in my pocket

    Most of the time when trying to answer a call with the phone in my pocket I end up starting one of the alternate options to answering because I can not see the screen until it is completely out and screen facing me.

    well see this thread http://forum.vodafone.co.uk/index.php?showtopic=29​866
    and this one http://digitalspy.co.uk/forums/showthread.php?t=10​67410
    i don't generally think someone is stupid for not immediately undersand the subtleties of how an n97 works. obviously you do.
    There's no dignity in begging for kudos. Do it for the karma.

  • Why can't I record calls with the iPhone?

    Hi,
    Why can't I record calls with the iPhone? Every other mobile can! That's quite pitty ...!

    Nonsense. There are many places where you are not allowed to take photos or video but those functions are included. Apple assumes no responsibility for them. Apple would not be responsible for managing the recordings on the phone either. It's most likely because Apple is located in California and in THAT particular state, both parties have to be informed of the recording. Most states do not require that. If Apple were located in another state (e.g. Alaska) there would be no restriction.
    All the apps that record calls store those recordings in their servers and charge you a fee. It would be preferable to have the calls stored only on the phone so no one else could access them. The iPhone has the technological capability; we have just been restricted from having this functionality without paying a 3rd party.

  • How do I answer calls with the KITKAT update?  I hit the flashing button but it's still ringing?  Where are the Answer settings?

    How do I answer calls with the KITKAT update?  I hit the flashing button but it's still ringing?  Where are the Answer settings?

    Aha!  Thank you!!!  That was not obvious. Sometimes I don't get the green and red icons.  So it's slide it to the right for answering and slide to the left for voice mail.

  • My iphone donot appear the name of the caller although the caller name saved on my mobile

    my iphone donot appear the name of the caller although the caller name saved on my mobile
    if i save any number with its name.......when its number call me the name donot appear

    Hello waleed101,
    I would recommend force closing all open apps on your iPhone, then restarting.
    iOS: Understanding multitasking
    http://support.apple.com/kb/HT4211
    iPhone, iPad, iPod touch: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/HT1430
    Cheers,
    Allen

  • Calls with no caller ID info still coming in...

    I have Verizon digital voice.  And this after having Vonage for years.  Oh, how I sometimes wish I had never changed.  Such as when I continually have phone calls ringing in that have "Unavailable" showing up on my TV screen and phone.  I have set up my account so that calls with no caller ID available won't even ring.  Perhaps someone here, another user or a VZ employee can explain this to me.  I NEVER got a call that came in with no caller ID info when I had Vonage.
    On another note, can someone else explain how numbers that are unpublished and unlisted, whether they are cell phones, home phones, or business phones, can be bought?  For example, I would be really ticked off to find out, after paying for an unlisted and unpublished number, that someone can type my phone number in and buy my name, address, etc.
    Thanks.

    *77, or Anonymous Call Rejection (ACR), only rejects call that would show on caller ID as "anonymous" or "private". These are calls where the incoming caller ID information is there, but the caller has chosen to block it from appearing on your caller id display. *77 cannot block calls where there is no caller ID information sent, such as "unavailable", "unknown",  or "out of area". These calls can only be screened with the optional feature Call Intercept.

  • Facing lot of problems with the DATA object  -- Urgent

    Hi,
    I am facing lot of problems with the data object in VC.
    1. I created the RFC initially and then imported the data object in to VC. Later i did some modifications to RFC Function module,and when i reload the data object, I am not able to see the new changes done to RFC in VC.
    2. Even if i delete the function module, after redeploying the IVIew, results are getting displayed.
    3. How stable is the VC?
      I restarted the sql server and portal connection to R3 is also made afresh.... still i am viewing such surprise results..
    please let me know what might be the problem.

    Hi Lior,
    Are u aware of this problem.
    If yes, please let me know...
    Thanks,
    Manjunatha.T.S

  • My iPhone 5, periodically,will not show the call waiting number. It beeps but will not give me the option to swicth over or show me who is calling. The call doesn't appear in my "recents" either.

    My iPhone 5, periodically,will not show the call waiting number. It beeps but will not give me the option to switch over or show me who is calling. The call doesn't appear in my "recents" either.

        We appreciate your feedback on this matter, gingerspice913. I've not come across this issue before.  Do you know how long it has been since the issue began? Please try to reset the network settings to see if it helps http://vz.to/1swAJbD?
    TamaraH_VZW
    Follow us on Twitter @VZWSupport

Maybe you are looking for

  • "Conversation" View in SMS Text Messages

    I am unable to change the settings in SMS text options to 'conversation' view. I followed the instructions on this help page but I didn't even havesome of the buttons that were mentioned. My other BB's (9300, Bold 9000) defaulted to conversation view

  • Two select lists in tabular form

    I have two Select Lists which one of them depends on the another -the second one's query depends on the first one's - ..... This operation can be done in a form or a page, but how it could be done in a tabular form??? Saad

  • Stock Determination

    I need the to take the reservation quantity into account while checking the stock in the warehouse, meaning that when i check the inventory stock (MMBE) i need the system to deduct the reservation quantity from the unrestricted use qty so that only t

  • INSTALL_ERROR_DISTRIBUTION_SIGNED_BY_APPLE : nothing works

    Hi, I've got an iMac 2011 with Snow Leopard (10.6.8), all software updates done. I've got the error INSTALL_ERROR_DISTRIBUTION_SIGNED_BY_APPLE while trying to get an app on AppStore... I tried to change as described in many comments the certificates

  • I'm seriously thinking about getting an iPod

    Okay, ever since I bought my Zen Micro, I've been having problem after problem with it... well, not since I got it... the first couple of weeks or so was great, and then there were problems. Firstly, there was the headphone jack problem, now it isn't