简体   繁体   English

Linux 中的 Java 进程状态

[英]Java process state in Linux

In Linux, many Java threads states are running, but their threads' parent Java process is sleeping.在 Linux 中,许多 Java 线程状态正在运行,但它们线程的父 Java 进程正在休眠。 Why?为什么?

For example, the Java process with pid is 5197:例如,pid 为 5197 的 Java 进程:

[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:但是 pid 5197 状态的线程是:

[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/....

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 .很可能5197main线程,根据这个答案,您可以通过运行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.您必须查看 Java 线程名称并将它们与 Jenkins 源代码协调。 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.看起来您正在处理 Jenkins 工作区内部的构建,在这种情况下, main可能是代理启动代码,而正在运行的线程可能是工作线程。

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM