JNI calls only work if sent from main thread?!?

Hi,
I searched through the forum for a couple of hours now, and found that a lot of developers seem to have problems with JNI and threads. However, I couldn't find a solution to my problem so far...hope you can help!
We need to send requests to a DDE Server from our Java application. For that reason, we implemented a very small DLL using Delphi, which calls the DDE Server and returns the result as a string. Using JNI, we call this DLL from Java.
Everything works fine, as long as we call the DDE Server (via JNI and the DLL) from the main thread of the Java application. But everytime we call it from another Java thread, our DDL reports that it can't get a connection to the DDE Server. This is especially awkward if you want to make calls as a reaction to GUI events, since then the call is sent by the Event Dispatch Thread of the Java runtime.
This does not seem to be a multi-threading problem, since we do never send multiple requests at the same time. It simply depends on the thread, from which the call is sent.
Any hints are appreciated very much.
Thanks!
Thilo

We are a step further now...thus the problem to be solved changed a little bit.
The former assumption, that connecting to the DDE server does only work from the main thread was false. It only seemed like that, because we called System.loadLibrary() to in the main thread to load the DLL . In fact, the connection to the DDE server works from any thread - you just have to make sure that System.loadLibrary() is invoked in this same thread.
This means: if System.loadLibrary() is invoked in the Event Dispatch Thread, we can call the DDE Server from this thread, which is what we primarily wanted to do. So our problem is solved.
Anyway, I made some more tests to find out, what happens if I start multiple threads, with each of them calling System.loadLibrary(). The result was, that only the first thread is successful. This means: the first thread, which loads the DLL is the only thread that is able to connect to the DDE server. All other threads won't get a connection.
What could be the reason for that?

Similar Messages

  • JNI Calling  a multithreaded C code from Java

    Hi,
    I am new to JNI . I am calling a multithreaded C (in which threads are created at runtime )code from a Java application (swing) on some event . The application crashes and it says "pthreads mutex_lock()". I have added -pthread as a command line argument .But even this does not help although the build is proper .It crashes at runtime .All other JNI calls are working perfectly ...
    Please help .
    Thanks in advance ...
    Regards
    Rohit

    Are any of those threads calling java code? If yes then are you calling the Attach method?

  • I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    Is it because the new itunes looks different.
    View > Show Sidebar
    Then it should work just the same as on your old computer.

  • My ipod only works 1meter away from router

    My ipod touch only works 1meter away from my BT Hub, how far should the wifi signal reach? my PC works at least14meters away, please help!

    Does it perform the same with other networks?
    1 meter is too short . Is the PC 4 or 14 meters? 4 meters is too short too
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on your router
    .- Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem with all networks then make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • Dell Inspiron 7537 - Sound only works after resuming from suspend

    Hello,
    So my sound does not work after boot, only once I resume from suspend. So, once I turn on my computer, and I load sound, nothing work (everything is unmuted in Alsa) - then if I suspend my computer and resume - the sound works every time.
    I use Alsa and here is my amixer output (before and after suspend is the same) :
    eric@archlinux ~> amixer
    Simple mixer control 'Master',0
    Capabilities: pvolume pswitch pswitch-joined
    Playback channels: Front Left - Front Right
    Limits: Playback 0 - 65536
    Mono:
    Front Left: Playback 5358 [8%] [off]
    Front Right: Playback 5358 [8%] [off]
    Simple mixer control 'Capture',0
    Capabilities: cvolume cswitch cswitch-joined
    Capture channels: Front Left - Front Right
    Limits: Capture 0 - 65536
    Front Left: Capture 11003 [17%] [on]
    Front Right: Capture 11003 [17%] [on]
    What gets rebooted when I do a suspend, but not when I reboot? Does not seem to make sense to me.
    Thanks.

    Is there any additional information I can include to help figure this out?

  • VideoPhoneLabs example, calling only working in one direction

    Hi all,
    I have started off with the VideoPhoneLabs example as provided by adobe and extended this sligthly further, however I have come accross a strange problem during testing.
    I am using two machines, both on my local network wirelessly, both with flash versions 10.1
    1 Vista 64-bit (Machine A)
    1 XP 32-bit (Machine B)
    The issues arrises when it comes to placing a call to another flash player instance (be it on the opposite machine or a seperate tab)
    A calling A - Works
    A calling B - Works
    B calling B - Works
    B calling A - Fails
    The failure is that the recipient machine doesn't appear to receive the 'call' and no option appears in order to accept or reject it.
    This occurs with out fail every time I try to call machine A from machine B, and always works any other way. I don't see how it can be a coding issue as they are all running exactly the same version, and I have stopped all firewall/protection programs. The are both connected wirelessly to the same router as well.
    If anyone has any clues/ideas, it would be great help.
    Regards
    Alistair

    Use the instructions in this article to clean the mouse.
    (15069)

  • People are unable to hear me when calling only works on speaker iPhone 4s AT

    I once made a called and my friend said that he was unable to hear me so I tested my iPhone by using voice memos and it couldnt find my voice, it only works on speaker.

    Bring your phone in for evaluation

  • Phone calls only work on speaker phone, phone calls only work on speaker phone

    my phone calls are not working regularly they are only working on speaker phone

    Try This...
    Close All Open Apps...  Perform a Reset... Try again...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430

  • Filter condition not working when Navigating from Main report to detail

    Hello,
    I have one report in OBIEE 10.3.4. Below is the filter condition used in Main report:-
    (Customer Secondary Organization is equal to / is in BMS OTHER C
    AND Customer Tertiary Organization is equal to / is in S&FO )
    OR Customer Secondary Organization is equal to / is in MKTG
    Also in my detail report I am using the same filter conditions:-
    (Customer Secondary Organization is equal to / is in BMS OTHER C
    AND Customer Tertiary Organization is equal to / is in S&FO)
    OR Customer Secondary Organization is equal to / is in MKTG
    Now when I am navigating from Main report to Detail report, then this filter condition is getting overridden by below condition:-
    Customer Secondary Organization is equal to MKTG
    and Customer Tertiary Organization is equal to S&FO
    or Customer Secondary Organization is equal to MKTG
    What I noticed is If I rearrange the filters and make it as below:-
    (Customer Secondary Organization is equal to / is in MKTG
    AND Customer Tertiary Organization is equal to / is in S&FO)
    OR Customer Secondary Organization is equal to / is in BMS OTHER C
    Then I am getting the filter in detail report as:-
    Customer Secondary Organization is equal to BMS OTHER C
    and Customer Tertiary Organization is equal to S&FO
    or Customer Secondary Organization is equal to BMS OTHER C
    It is taking Secondary Organization which is 2nd one in the main report.
    Can anyone please help me on this.
    Thank You,
    Shivam Saxena

    Hi,
    What you can try is refer the filte condition in the main report to the detailed report with the option--> Filter based on another request.
    Or you try creating another intermediate report which will refer the main report filters and pass the filters to the detailed report.
    Hope this helps.
    Regards
    MuRam

  • Picture text not working when sent from iPhone to non iPhone

    Since this 6.1 update that I have told everyone not to update. My phone has been doing strange things and I have called and talked to apple and they said they have not heard anything about it. First off, when I try to send a picture text to someone that does not have an iPhone such as an android they either a) can't open it or b) it opens as a video and flashes off. They had no problems before this update. So today my iMessage stopped working. I deletes the messages I had and sent a test text to iPhone friends and it started working. I also went I to settings and added my email to iMessage. In doing this it got me to thinking that if this changed by itself maybe it had something to do with the SMS.  Which is turned on already. I turned off iMessage and sent picture text to non iPhone and it worked. I don't want to have to turn off and no all the time anyone else had this problems?

    Hi Steve,
    I have tried to export to epub 2 and 3. The video is MP4 (h264). It was working just fine on all devices now I can't seem to get any video to export and work.
    Pretty sure it all stopped working after the Yosemite upgrade on the Mac or iOS 8 on devices. Or maybe both.
    Oddly, it plays in iBooks on my mac, just not on the iPad or iPhone.
    I've also tried to just export a couple of short test epubs with vids in different formats but get the same result....not working.

  • IPod 4 only working when conected to mains after battery replacment and stuck in recovery mode when conected to power

    HI, 
    i have replaced the screen and battery on my iPod 4 i then tested it and it was working so i sealed it closed. (still working after sealed) (when new batterys are installed it is normally reccomended that you give them a full battery cycle for optium battery life), so i let it die. after this i put it on charge and the lightening bolt sign for charging came on, i left it for a full day and no change in battery life and when disconected it died so i plugged it into the pc and this continued so i reset it a few times then it decided to loop the apple sign when conected to power. i put it into dfu mode (the only time the pc reconises it) and went to restore it and it came up error 21 (i think) and now is stuck in recovery mode and dies when disconected from power. Lots of probs 
    any help would be apreacheated. thanks

    Take it to somebody with more experience fixing iPods.

  • My JSP only works when run from its project

    I have managed to make a JSP which correctly displays values from the database when I do right-click/run from the project it is in.
    However if I do right-click/run on the JSP page directly all the bindings are empty. The aim eventually is to deploy to Tomcat, so I will need the JSP to work on its own.
    Am new to all of this (java,tomcat,jdev) so all the code has been genereated by jdeveloper - obviously I have set-up some config incorrectly but I can't find where.
    Any help appreciated!
    Thanks,
    Louise

    Assuming that you are using ADF and Struts for this application:
    The trick is that you actually need to run the struts action that is created for your Datapage.
    When you right click on the jsp file in the Struts diagram and choose run - it actually invokes the struts action - if you look at the log window you'll see the URL invoked ends with .do

  • 160gb classic, only working when attached to mains power outlet

    In last 24 hrs my classic has decided to only switch on when plugged into mains outlet. Screen flickers when attached to laptop, had to restart computer to get it to switch on and sync. I have tried restoring to factorysettings before synching tunes back to it. Anyone out there who to can resolve this before I have to pay for repairs?

    Take it to somebody with more experience fixing iPods.

  • Calls only work on speakerphone

    I've read several tips from others about this problem (cleaning the headset jack, switching back and forth between speakerphone and regular, etc.).  None of them have worked...

    Are there any bluetooth devices connected? Have you tried inserting and removing the headphone plug several times? Have you restarted the phone by holding the HOME and SLEEP buttons until an Apple logo appears? Have you checked that the mute switch on the left edge of the phone is not set to mute? Have you adjusted the volume?

  • Local ref garbage collection within "nested" JNI calls

    I am using a JVM started in C++ to make calls to java classes. The C++ code makes JNI call into the JVM which instantiates a java class. The java class, in the course of execution, makes other JNI calls. All this happens on one thread of execution.
    What I am seeing is that local references from the native methods being called by the java class are not being released until the initial C++ native call exits. The JNI spec (text included below) seems to indicate there is registry of "nonmovable local references to Java objects" which "keeps the objects from being garbage collected". Is there only one such registry which does not get deleted until the initial C++ native call exits? If so, this would explain what I am seeing. How do I get around it?
    Thanks,
    Iztok
    From the JNI spec:
    "To implement local references, the Java VM creates a registry for each
    transition of control from Java to a native method. A registry maps nonmovable local references to Java objects, and keeps the objects from being garbage collected. All Java objects passed to the native method (including those that are returned as the results of JNI function calls) are automatically added to the registry. The registry is deleted after the native method returns, allowing all of its entries to be garbage collected."

    When I say "initial" I mean the initial C++ JNI call into a JVM running in a C++ process as shown in the pseudo code below. initNativeFunc() makes a call to Foo.doSomething() function which calls nativeFunc2 (another native function). Only a local reference to Retval was created in nativeFunct2, so when nativeFunct2 returns and the Retval is no longer used in Foo it should be a candidate for garbage collection. But this is not what happens. The Retval from nativeFunc2 is not being cleaned up until Foo.doSomething() returns. If I make the loop in Foo.doSomething() long enough, NewDoubleArray() returns a NULL when it runs out of memory.
    void initNativeFunc() {
    jclass clazz = env->FindClass("Foo");
    jmethodID mid = env->GetMethodID(clazz, "doSomething", "()V");
    env->CallVoidMethod(clazz, mid, ...);
    JNIEXPORT jobject JNICALL nativeFunc2() {
    jclass clazz = env->FindClass("Retval");
    jmethodID mid = env->GetMethodID("Retval, "<init>", "()V");
    jobject retval= env->NewObject(clazz, mid);
    jdoubleArray da = env->NewDoubleArray(100000);
    jfieldID fid = ...
    env->SetObjectField(retval, fid, da);
    return retval;
    public class Foo {
    public native void nativeFunc2();
    public void doSomething() {
    for (int i = 0; i < 100; i++) {
    Retval retval = nativeFunc2();
    }

Maybe you are looking for

  • Window - No Disk Message when Syncing

    Quite often I get a Windows - No Disk error message when syncing a new CD to my Ipod Classic 160GB. The box has a message saying "There is no disk in the driver. Please insert a disk into drive G." Drive G is a port for the USB connecting cable and d

  • Java 7 not working on OSX 10.8.3

    I need some help with Java 7. I am trying to open my photo lab software, however, it keeps giving me a message saying I need to download the Java Runtime Environment. I clicked on the link and it brought me to the Java site. I sucessfully download th

  • Problem using stacks in CS4

    So I want to try to edit in  stacks but cant seem to get it to work. my  understanding is the the usual command is file, scripts, load into stack  and then once your files load you go file, scripts, statistics, my  problem is that there is not file,

  • Raw files transfer to dvd for tv

    i have 1000s of raw files on seperate hdr drives  i want to put some on to a dvd disk which i can the play on my tvs dvd.do they  have to be converted to jpeg .what procces do i do

  • Photoshop can't save files because of a program error

    Annoying!!