In a JNI native method, is there a way to know the ID of the current thread without calling Java back? Thread-local storage would also work.
EDIT: pthread.h is present in the NDK include folder… Does anyone know if Java threads correspond to POSIX ones in the NDK implementation?
Which ID are you interested in? A Dalvik thread dump includes this:
“tid” is the VM’s ID.
“handle” is the pthread_t.
“sysTid” is the result of gettid() (the Linux process ID).
The libcore thread ID (obtained from java.lang.Thread.getId()) is not shown.
(You can obtain the above with “adb shell kill -3 “. The output goes to a common file, defined by the dalvik.vm.stack-trace-file property — usually /data/anr/traces.txt, but it varies by device.)
EDIT: Every Dalvik VM thread is a Linux pthread. The gettid() syscall will give you a unique ID for each thread. Also, you can add identifying information to TLS in java.lang.Thread or pthread_key.