I'm using JDK 1.4.2_07 in Solaris UNIX. I've a multi-threaded application and I wanted to measure the CPU usage of every thread from Java. I wrote a Native C application that could return me the CPU usage of the thread given the process id and the thread id. But I'm not sure of how to get the current thread id so that it can be passed on to the native applcation. I'm able to get the current thread name (+ the current process id) and I'm not sure how to get the thread id using this information. It would be of great help, if somebody could help me in getting the thread id.
currentThread.getName() returns me the name of the current thread. But there is something called as id associated with every thread (this info can be obtained from /proc/<process id>/lwp/ directory, which will contain the list of directory for every lwps or threads). My basic requirement is to find the mapping between the name that is maintained by Java and the id maintained by the OS.
Java does not give you a way to get the native thread ID. One reason is that there is no guarantee of a one-to-one correspondence between Java threads and native threads. In the early days of Java, there were "green threads", where one native thread served many Java threads; I don't know if they are still supported or used much.
If you really need the native thread ID, you'll have to write native code and use JNI.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.