title: What is obj in MonitorEnter?
body: <p>I am not sure what obj is in MonitorEnter JNI function. Is it obj passed as parameter in native function or shared variable which I want to synchronize?
  I have a variable called buffer which is shared by two threads.
  This is my code.</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_company_com_HelloActivity_setBuffer(JNIEnv *env, jobject obj, jstring jstr)
  {
      char buf[256];
  
      int len = (*env)-&gt;GetStringLength(env, jstr);       
      (*env)-&gt;GetStringUTFRegion(env, jstr, 0, len, buf);
      (*env)-&gt;MonitorEnter(env, obj); // I don't think this is correct.
      strcat(buffer, buf); // buffer is declared as global char buffer[256];
      (*env)-&gt;MonitorExit(env, obj);
  }
  </code></pre>
  
  <p>EDIT:
      How about this? syncobj is defined in Activity as static Object and shared with another thread.</p>
  
  <pre><code>JNIEXPORT void JNICALL Java_company_com_HelloActivity_setBuffer(JNIEnv *env, jobject obj, jstring jstr, jobject syncobj)
  {
      char buf[256];
  
      int len = (*env)-&gt;GetStringLength(env, jstr);       
      (*env)-&gt;GetStringUTFRegion(env, jstr, 0, len, buf);
      (*env)-&gt;MonitorEnter(env, syncobj);
      strcat(buffer, buf);
      (*env)-&gt;MonitorExit(env, syncobj);
  }
  </code></pre>