Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matching Java thread-ID to native Linux PID - Sun Java 1.5.x

1,848 views
Skip to first unread message

Federico Cozzi

unread,
Nov 22, 2010, 8:07:11 AM11/22/10
to
Hello,
I am running a J2EE app on Linux using Sun Java 1.5.x.
Is there a way to match Java thread-ID to native Linux PID?
According to top ("top -H") there are some Java threads running at
100% CPU and this is wrong.
I would like to debug this and the first step is understanding which
threads I should investigate.
(BTW, what is the second step? getting a stack-trace?)
This is a production environment, therefore my analysis should not
interfere with the running app

Thanks,
Federico

Nigel Wade

unread,
Nov 22, 2010, 8:27:16 AM11/22/10
to

ps -Lef

will show every LWP along with the associated PID and PPID.

Then it's just a matter of finding the right line in the many, many
lines of output. You can help reduce the output with suitable use of the
usual culprits such as 'grep' and 'awk'.

--
Nigel Wade

Federico Cozzi

unread,
Nov 22, 2010, 9:44:05 AM11/22/10
to
On 22 Nov, 14:27, Nigel Wade <nmw-n...@ion.le.ac.uk> wrote:
> ps -Lef
> will show every LWP along with the associated PID and PPID.

This outputs only Process ID (and Parent Process ID), which is an OS-
level ID.

I need to correlate this output to Java Thread-ID, which is a JVM-
level ID (starts from 1 when the JVM is started) and is what most Java
tools use. Under Java a thread has both a thread-name and a thread-ID;
if the JVM uses native threads (like Sun Java 1.5 on Linux) each Java
Thread is mapped to a Linux LWP, but IDs are different.

Bye,
Federico

Nigel Wade

unread,
Nov 22, 2010, 10:15:43 AM11/22/10
to
On 22/11/10 14:44, Federico Cozzi wrote:
> On 22 Nov, 14:27, Nigel Wade <nmw-n...@ion.le.ac.uk> wrote:
>> ps -Lef
>> will show every LWP along with the associated PID and PPID.
>
> This outputs only Process ID (and Parent Process ID), which is an OS-
> level ID.

It outputs the PID, the PPID and the LWP id. The LWP id is what 'top -H'
shows in the PID field, which is what you need to map a thread to the
actual PID.

>
> I need to correlate this output to Java Thread-ID, which is a JVM-
> level ID (starts from 1 when the JVM is started) and is what most Java
> tools use. Under Java a thread has both a thread-name and a thread-ID;
> if the JVM uses native threads (like Sun Java 1.5 on Linux) each Java
> Thread is mapped to a Linux LWP, but IDs are different.

It appears I misunderstood your post. I thought you wanted to identify
which Java process was running the the theads in question so you could
attach a Java debugger to the correct process. I'm sorry, I have no idea
how Java thread id's relate to the LWP id.

--
Nigel Wade

Patricia Shanahan

unread,
Nov 22, 2010, 10:19:27 AM11/22/10
to

My first try at this would not involve the mapping at all. I would run
the program under Eclipse in debug mode, bring it to as idle a state as
possible, and then monitor the debug display to see which threads are
running all the time. You would immediately be able to pause the run and
check what each thread is doing.

Patricia

markspace

unread,
Nov 22, 2010, 3:15:43 PM11/22/10
to
On 11/22/2010 7:19 AM, Patricia Shanahan wrote:

> My first try at this would not involve the mapping at all. I would run
> the program under Eclipse in debug mode,


Patricia makes a good point. The first step in most debugging
investigations is to reproduce the problem. Poking at the live server
is likely to be difficult at best, with the restrictions placed on you
to not actually disturb the production environment and what not.

Playing with threads and debugging can vary with the actual container
used, which you didn't mention. Are you using JBoss? Tomcat?
Websphere? What version?

Lew

unread,
Nov 22, 2010, 5:04:01 PM11/22/10
to
Federico Cozzi wrote:
>> I am running a J2EE app on Linux using Sun Java 1.5.x.
>> Is there a way to match Java thread-ID to native Linux PID?
>> According to top ("top -H") there are some Java threads running at
>> 100% CPU and this is wrong.
>> I would like to debug this and the first step is understanding which
>> threads I should investigate.
>> (BTW, what is the second step? getting a stack-trace?)
>> This is a production environment, therefore my analysis should not
>> interfere with the running app
>

Patricia Shanahan wrote:
> My first try at this would not involve the mapping at all. I would run
> the program under Eclipse in debug mode, bring it to as idle a state as
> possible, and then monitor the debug display to see which threads are
> running all the time. You would immediately be able to pause the run and
> check what each thread is doing.
>

Other IDEs work similarly.

--
Lew

Federico Cozzi

unread,
Nov 24, 2010, 1:57:02 PM11/24/10
to

We are using Glassfish 2.1.1
I can't reproduce it in debugging environment, since it happens very
rarely (once every two months or so) after a lot of load on the
application server (it's a production server after all)
It could even be that it's not an "application" thread (i.e. a thread
serving web requests) but a thread which is internal to the
application server itself.

I hoped that matching java thread-IDs to native linux PIDs was
easier...

Bye,
Federico

markspace

unread,
Nov 24, 2010, 7:18:25 PM11/24/10
to
On 11/24/2010 10:57 AM, Federico Cozzi wrote:

> We are using Glassfish 2.1.1
> I can't reproduce it in debugging environment, since it happens very
> rarely (once every two months or so) after a lot of load on the
> application server (it's a production server after all)


We get a lot of different levels of experience here; it's a knee-jerk
reaction I think for folks to start with remedial advice.

Does this link help you? It's almost the holidays here and I don't have
time to check it out personally.

<http://docs.sun.com/app/docs/doc/820-4339/6nfqftsnj?l=en&a=view>


P.S. I searched with Google for "glassfish thread dump"

Patricia Shanahan

unread,
Nov 24, 2010, 7:33:06 PM11/24/10
to

Have you looked at the Glassfish performance monitor?

Patricia

markspace

unread,
Nov 24, 2010, 8:03:31 PM11/24/10
to
On 11/24/2010 10:57 AM, Federico Cozzi wrote:
> I hoped that matching java thread-IDs to native linux PIDs was
> easier...


Just found this poking around late today. It describes how to match a
Solaris thread to a Java thread. I wonder if other 'nix are similar?

<http://www.camelrichard.org/matching-java-thread-nid-tid-solaris-10-threads-using-pstack>

It seems based on the "nid" of the Java thread dump. nid = native ID
perhaps?

ske...@relianceco.com

unread,
Jul 31, 2019, 6:51:53 PM7/31/19
to
9 years later.... I just confirmed that yes: "nid" in jcmd threaddump output from JDK 1.8 is indeed a hex encoded value of the Linux system PID on an Ubuntu server. We had a thread in the threaddump nid=760 and this correlated to Linux PID 1888 correctly.

0 new messages