1

I have created a typical SpringBoot application which is using Spring Framework's Restful library. As well as having some @RestController(s) and @Service(s) beans on it.

My question now is not more on the usage and implementation of Spring and Springboot components but rather this one:

My question is that, when I launch a single Springboot application it spawns a lot of Light Weight Processes (LWP). Which I think 1 LWP is one Java Thread.

Here is a screenshot: enter image description here

In particular I would like to know if how can I get the LWP ID of a particular thread? So in this case I would like to know which Java Thread is associated to LWP ID 11791.

Because currently I have a problem where my Springboot application hangs up/crashes and one of its subprocess(es) has been running for hours.

When we killed that particular subprocess(es) the server will no longer hang up.

Artanis Zeratul
  • 963
  • 2
  • 14
  • 40
  • I am thinking this might be the answer to my question: https://stackoverflow.com/questions/25502812/why-does-java-spawn-so-many-processes. Cheers :D – Artanis Zeratul Nov 30 '18 at 02:32
  • But still the question of how to get the Process ID of an executed line code is still not answered by that link. – Artanis Zeratul Nov 30 '18 at 03:23
  • Those aren't processes, but threads. Java applications always uses multiple threads (even if the application itself is single-threaded, which is definitely not the case for spring boot). – Mark Rotteveel Nov 30 '18 at 15:33
  • Hi @MarkRotteveel, thanks a lot for your answer. I really appreciate it. I am very aware that they are threads. But I am also thinking they are processes at the same because they were assigned with PIDs by the OS when I did 'htop' command in CentOS 7 Isn't this both a thread and a process instead? By the way, I agree that one of my question is duplicate here but there one more which is how to get the Process ID of a java thread. Cheers. – Artanis Zeratul Dec 02 '18 at 05:36
  • And that is why you should restrict yourself to asking only one question per question, but in any case. You can't get process ids of threads in Java itself (AFAIK), because - as also explained in the duplicate - it is a Linux specific implementation choice to model a thread as a light-weight sub-process. Java doesn't care about that implementation choice (early Java even had 'green threads' on some platforms, where multiple Java threads were scheduled on a single OS thread). In any case, I added another duplicate that shows you how it can be done using JNI. – Mark Rotteveel Dec 02 '18 at 07:53
  • @MarkRotteveel, my apologies, I didn't know that Centos 7 x64 is will create an Light Weight Process ID for each thread (although I am not sure) but I am suspecting it is. And if I am correct, I would like to know how to get the LWP ID of a particular thread in Java. – Artanis Zeratul Dec 03 '18 at 04:00
  • There is nothing in Java itself; the second duplicate shows how it can be done with JNI and some native code. – Mark Rotteveel Dec 03 '18 at 07:39
  • @MarkRotteveel, the JNI answer compiles and works (with my additional instruction) but you will have to modify your JAVA_HOME which I don't think is a good idea. Is it? – Artanis Zeratul Dec 03 '18 at 10:35
  • You don't **need** to change your JAVA_HOME. In that answer it is only to simplify the compilation. – Mark Rotteveel Dec 03 '18 at 15:43

0 Answers0