Search Results

Search found 2 results on 1 pages for 'jary'.

Page 1/1 | 1 

  • notify listener inside or outside inner synchronization

    - by Jary Zeels
    Hello all, I am struggling with a decision. I am writing a thread-safe library/API. Listeners can be registered, so the client is notified when something interesting happens. Which of the two implementations is most common? class MyModule { protected Listener listener; protected void somethingHappens() { synchronized(this) { ... do useful stuff ... listener.notify(); } } } or class MyModule { protected Listener listener; protected void somethingHappens() { Listener l = null; synchronized(this) { ... do useful stuff ... l = listener; } l.notify(); } } In the first implementation, the listener is notified inside the synchronization. In the second implementation, this is done outside the synchronization. I feel that the second one is advised, as it makes less room for potential deadlocks. But I am having trouble to convince myself. A downside of the second imlementation is that the client might receive 'incorrect' notifications, which happens if it accessed the module prior to the l.notify() statement. thanks a lot

    Read the article

  • JNI: Passing multiple parameters in the function signature for GetMethodID

    - by Jary
    I am trying to execute a function in Java (from C) that has the following signature: public void execute(int x, int y, int action); My problem is to define the function signature in GetMethodID: env->GetMethodID(hostClass, "execute", "(I;I;I;)V"); The problem I ma getting is: W/dalvikvm( 1849): Bogus method descriptor: (I;I;I;)V W/dalvikvm( 1849): Bogus method descriptor: (I;I;I;)V D/dalvikvm( 1849): GetMethodID: method not found: Lcom/device/client/HostConnection;.execute:(I;I;I;)V I am not sure how to specify the method signature in GetMethodID (for 3 integers as parameters). I saw people use the ";" to separate parameters in other posts for the String and File class, but nothing with primitives like integer. What would be the correct way to do this please? Thank you.

    Read the article

1