title: JNI system.out and printf behaviour
body: <p>I am writing a program that uses JNI to interface with a simple c program. I have created the following programs:</p>
  
  <pre><code>public static void main(String[] args) {
      Hello h = new Hello();
      System.out.println("before");
      int number = h.sayHello();
      System.out.println(number);
      System.out.println("after");
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>JNIEXPORT int JNICALL Java_Hello_sayHello (JNIEnv *env, jobject obj) {
       printf("Hello JNI\n");
       return 10;
  }
  </code></pre>
  
  <p>To my surprise this program returns:</p>
  
  <pre><code>before
  10
  after
  Hello JNI
  </code></pre>
  
  <p>To me this is very strange because it is clear that the c program is executed between the "before" and "after" statement (The number 10 is printed). But why is the printf statement not executed when it is called. Is it somehow blocked by the jvm because only one program is allowed to write to the output at the same time? Is there a way to correct this behavior?</p>