0

I have to call some static java methods from c.

SOME-C-CODE
(*g_env)->CallStaticVoidMethodA(g_env, g_obj, g_mid, val);
SOME-C-CODE
(*g_env)->CallStaticVoidMethodA(g_env, g_obj, g_mid, val);
SOME-C-CODE
(*g_env)->CallStaticVoidMethodA(g_env, g_obj, g_mid, val);
SOME-C-CODE

I have to call java methods several times at different places. But the code executes all the java methods first and then comes to executing the native code. Please tell me how I can run the code in the execution sequence required ?

P.S. I've cached the jvm, jobject and jmethod and attaching them to current thread using AttachCurrentThread and DetachCurrentThread

3
  • 1
    How do you know that all Java methods are executing first? If you just printing logs to console, you need to know that Java System.out.println() and C printf() are buffered, and they have different buffers, so your output might be just messed up, so you might need to call System.out.flush() and fflush(stdout) each time you print a line of text. Commented Apr 14, 2015 at 18:28
  • Thanks a lot @pelya. The problem was related to buffer and it is working now Commented Apr 14, 2015 at 19:34
  • possible duplicate of How do I redirect terminal output from a C program to System.out with JNI? Commented Apr 17, 2015 at 23:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.