Reputation: 13
In Linux, many Java threads states are running, but their threads' parent Java process is sleeping. Why?
For example, the Java process with pid is 5197:
[root@ov7-ops-test-99 tmp]# ps -eo pid,s,lwp,command|grep activity
5197 S 5197 java -jar /opt/work/jenkins/workspace/.......
but threads with pid 5197 state is:
[root@ov7-ops-test-99 tmp]# ps -eLo pid,lwp,s,%cpu,%mem,command|awk '/activity/ {if(index($3,"R")>0){print $1,$2,$3,$4,$8}}'
5197 5303 R 0.4 /opt/work/jenkins/workspace/....
5197 5563 R 0.5 /opt/work/jenkins/workspace/....
5197 7326 R 1.4 /opt/work/jenkins/workspace/....
5197 7330 R 1.4 /opt/work/jenkins/workspace/....
5197 7334 R 1.4 /opt/work/jenkins/workspace/....
5197 7338 R 1.4 /opt/work/jenkins/workspace/....
5197 7339 R 1.4 /opt/work/jenkins/workspace/....
5197 7340 R 1.4 /opt/work/jenkins/workspace/....
5197 7345 R 1.4 /opt/work/jenkins/workspace/....
5197 7346 R 1.4 /opt/work/jenkins/workspace/....
5197 7349 R 1.5 /opt/work/jenkins/workspace/....
5197 7357 R 1.4 /opt/work/jenkins/workspace/....
5197 7360 R 1.4 /opt/work/jenkins/workspace/....
5197 7365 R 1.4 /opt/work/jenkins/workspace/....
5197 7368 R 1.4 /opt/work/jenkins/workspace/....
5197 7369 R 1.4 /opt/work/jenkins/workspace/....
5197 7370 R 1.4 /opt/work/jenkins/workspace/....
Upvotes: 1
Views: 348
Reputation: 44942
Either the parent thread started worker threads and then went to sleep or you are observing background tasks doing the work. Most likely 5197
is the main
thread, as per this answer you can confirm it by running jps -v
.
There is not enough details in your example. You would have to look at the Java thread names and reconcile them with Jenkins source code. It looks like you are dealing with builds inside the Jenkins workspace in which case the main
could be the agent startup code and running threads could be the workers.
The below code causes the same process state that you observed:
public static void main(String[] args) throws Exception {
Thread t1 = new Thread(() -> {
int i = 0;
while (true) {
i++;
}
});
t1.start();
t1.join();
}
Upvotes: 1