access java synchronized method from native code

Eric Moors :

I have a java class that has some (private static) synchronized methods which I want to call from native code as well. with some example code it becomes more clear what I mean

public class SomeClass {
   private static synchronized void method() {
     //do something that needs synchronization
   }
}

and the associated native code (C++)

void someFunction(JNIEnv * env) {
   jclass someClass = env->findClass("SomeClass");
   jmethodID methodId = env->GetStaticMethodID(jclass, "method", "()V");
   env->MonitorEnter(jclass); // <--- IS THIS NEEDED/ALLOWED
   env->CallStaticVoidMethod(jclass, methodId);
   env->MonitorExit(jclass); // <--- IS THIS NEEDED/ALLOWED
}

So what I am wondering is if I need to call MonitorEnter/MonitorExit, or if the method synchronization is enforced already by the synchronized attribute on SomeClass.method(). I am not so much interested in rewriting the code. I can think of a few solutions to work around this, but I am interested in what the behaviour is, given a synchronized method that is called from native code.

qbert220 :

Section 8.4.3.6 synchronized Methods of the Java Language Specification says that declaring the method synchronized has the same effect as adding a synchronized block within the method.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java - How to access static synchronized method from another Thread?

From Dev

Java synchronized method is not synchronized

From Java

What Cases Require Synchronized Method Access in Java?

From Java

Object in Synchronized code returned from a method

From Java

Which is the fastest way to access native code from Java?

From Java

Call a static java method of another package from native code

From Dev

Calling a Java Method from the native code using jni

From Java

Why synchronized in static method and in Class get different java byte code

From Dev

Java synchronized method usage

From Java

Java synchronized method

From Java

java synchronized on method Not working?

From Dev

Accessing synchronized method in java

From Dev

Understanding synchronized method in JAVA

From Java

Java native method source code

From Dev

Calling a synchronized method from a new thread created inside another synchronized method of the same class in Java

From Dev

Synchronized method ans synchronized blocks in Java

From Dev

Android Access Same instance method on activity from different threads without locking. Added synchronized method

From Java

File access synchronized on Java object

From Dev

Java volatile necessary with synchronized access?

From Dev

Java synchronized method with expensive parameters

From Dev

Java Synchronized method is not locking object

From Dev

Access native code from my own language

From Java

Is it safe to call a synchronized method from another synchronized method?

From Java

What is the synchronization cost of calling a synchronized method from a synchronized method?

From Dev

Code generated by Java synchronized function

From Dev

Unable to access protected final synchronized method in a class

From Dev

How to Access React Native Assets from Native Code

From Dev

How to resolve a Bad global or local ref passed to JNI error when calling a java method from native code

From Dev

@Async method inside synchronized method Java

Related Related

  1. 1

    Java - How to access static synchronized method from another Thread?

  2. 2

    Java synchronized method is not synchronized

  3. 3

    What Cases Require Synchronized Method Access in Java?

  4. 4

    Object in Synchronized code returned from a method

  5. 5

    Which is the fastest way to access native code from Java?

  6. 6

    Call a static java method of another package from native code

  7. 7

    Calling a Java Method from the native code using jni

  8. 8

    Why synchronized in static method and in Class get different java byte code

  9. 9

    Java synchronized method usage

  10. 10

    Java synchronized method

  11. 11

    java synchronized on method Not working?

  12. 12

    Accessing synchronized method in java

  13. 13

    Understanding synchronized method in JAVA

  14. 14

    Java native method source code

  15. 15

    Calling a synchronized method from a new thread created inside another synchronized method of the same class in Java

  16. 16

    Synchronized method ans synchronized blocks in Java

  17. 17

    Android Access Same instance method on activity from different threads without locking. Added synchronized method

  18. 18

    File access synchronized on Java object

  19. 19

    Java volatile necessary with synchronized access?

  20. 20

    Java synchronized method with expensive parameters

  21. 21

    Java Synchronized method is not locking object

  22. 22

    Access native code from my own language

  23. 23

    Is it safe to call a synchronized method from another synchronized method?

  24. 24

    What is the synchronization cost of calling a synchronized method from a synchronized method?

  25. 25

    Code generated by Java synchronized function

  26. 26

    Unable to access protected final synchronized method in a class

  27. 27

    How to Access React Native Assets from Native Code

  28. 28

    How to resolve a Bad global or local ref passed to JNI error when calling a java method from native code

  29. 29

    @Async method inside synchronized method Java

HotTag

Archive