Get JNIEnv in thread-aware manner.