title: JNI - multi threads
body: <p>I have a JNI wrapper for Java functions that are called from C...  I'm trying to call some methods from different threads and I get an error when trying to get a new copy of the JNIEnv pointer... the code I'm using is below and is called in each method: </p>
  
  <pre><code>        JNIEnv* GetJniEnvHandle(){
          ThreadInfo();
          JNIEnv *envLoc; 
          //if(Thread::CurrentThread-&gt;IsBackground || Thread::CurrentThread-&gt;IsThreadPoolThread)  
          jint envRes = vm-&gt;GetEnv((void**)&amp;envLoc, JNI_VERSION_1_4);
          if(envRes == JNI_OK){
              if(ThreadId != Thread::CurrentThread-&gt;ManagedThreadId)
                  jint res = vm-&gt;AttachCurrentThread((void**)&amp;envLoc, NULL);
          }else{          
              Log("Error obtaining JNIEnv* handle");  
          }
          return envLoc;
      }
  </code></pre>
  
  <p>The JVM has already been instantiated and this (and other methods) run when being called from the main/initial thread.  When I get a value for envRes it holds a -2 when in a sub-thread.</p>