3

I need to match java thread ids to its native linux pids. I can't use kill -3 <PID> because I don't own to output stream or jstack <PID> because I'm running with JRE and not JDK.

Tried pstack from the linux side, and JVM Management classes from java side - without any success.

Your assistance is appreciated.

Thanks.

shaiis.com
  • 244
  • 4
  • 10

1 Answers1

3

The Thread id is not related to the underlying OS thread id. It is a value assigned to that Thread instance from a static counter.

/* For generating thread ID */
private static long threadSeqNumber;

private static synchronized long nextThreadID() {
    return ++threadSeqNumber;
}

You will need to use some native call to get the actual value, possibly with what's proposed in Juned's link in the comments.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724