AttachCurrentThread() in an already-attached thread harmless?

To work with various APIs, it's sometimes convenient (or necessary) not to pass around the JNIEnv argument all over the place. If I call some function that's running in the same thread and that function calls AttachCurrentThread() to get the current JNIEnv pointer, is that (a) harmless, (b) inexpensive, especially in loops (i.e., basically a no-op since the current thread is already attached)?

- Paul

[418 byte] By [pauljlucasa] at [2007-10-3 9:43:55]
# 1

It is harmless to call AttachCurrentThread multiple times in the same thread. but 1.) I wouldn't say it is inexpensive (you have an up call into the VM, some kind of look-up has to be done and 2.) If a function is in a loop and calls AttachCurrentThread function in that loop, then it is bad style - instead they should call the attach function outside the loop.

jim.marshalla at 2007-7-15 5:00:19 > top of Java-index,Java HotSpot Virtual Machine,Specifications...