Is there a way of finding the mapping between Java threads and POSIX threads on Linux for a multi-threaded application written in Java?
From my research, there is a 1:1 correspondence between each user-thread created in Java's OpenJDK and kernel threads via the NPTL. Assuming the above is correct, what would need to be done to hook into the JVM's native thread delegation mechanism to get each thread's POSIX id?
The motivation for getting each thread's id would be to inspect each thread's affinity, to get per-thread CPU times, and context-switch times at a specified sampling rate at runtime.
Although not a very experienced C/C++ developer, I would preferably like to write this in native code for learning purposes rather than using a more generic utility with a wider interface than what is necessary.
Any help is greatly appreciated.