>>>>> John Rousseau writes:
John> On Tuesday Mar 28, 2000, Norman Shapiro wrote:
>> The Java jni specifications require a JNIEnv* for almost all
>> functions they provide. Furthermore it seems that if multiple
>> Java threads can access the same function, each function call must
>> use the JNIEnv* from the current thread.
>>
>> Given that function I am writing is maybe 20 deep in a call
>> hierarchy of C++ functions I have written, is there any way of
>> accessing the correct JNIEnv* short of passing it all the way down
>> as C++ function arguments?
>>
>> Putting it in a global or within a global class does not work in
>> my case because multiple Java threads can be using the same C++
>> function.
>>
>> I need a solution that works under Linux, though something that is
>> portable to Microsoft* would be ideal.
John> You could save the pointer in thread local storage, but I guarantee
John> that it won't be portable.
John> Take a look at pthread_key_create, pthread_setspecific, et al.
A more portable approach is to use JNI_GetCreatedJavaVMs() and
AttachCurrentThread(). If the calling thread is already a java thread
AttachCurrentThread() will return its JNIEnv.
Juergen
--
Juergen Kreileder, Blackdown Java-Linux Team
http://www.blackdown.org/java-linux.html
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]