创建名为"{java}"的线程(即轻量级进程)是为了什么? [英] What are threads (i.e. lightweight processes) named `{java}` created for?

查看:77
本文介绍了创建名为"{java}"的线程(即轻量级进程)是为了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个Java程序,它会睡一会儿:

I wrote a Java program that sleeps for a while:

package com.mycompany.app;

import java.lang.System;
import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) {
    System.out.println("the current process's pid is " + ProcessHandle.current().pid());
    try {
        TimeUnit.SECONDS.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Hello World!"); // Prints the string to the console.

    }
}

我运行以下程序:

$ java -cp target com.mycompany.app.Main 
the current process's pid is 10172

我检查了Ubuntu创建的运行它的过程:

I inspect the processes that Ubuntu creates to run it:

$ pstree -pau -l -G -s 10172
systemd,1 splash
  └─lxterminal,3194,t
      └─bash,12150
          └─java,10172 -cp target com.mycompany.app.Main
              ├─{java},10173
              ├─{java},10174
              ├─{java},10175
              ├─{java},10176
              ├─{java},10177
              ├─{java},10178
              ├─{java},10179
              ├─{java},10180
              ├─{java},10181
              ├─{java},10182
              ├─{java},10183
              ├─{java},10184
              ├─{java},10185
              ├─{java},10186
              ├─{java},10187
              ├─{java},10188
              ├─{java},10189
              └─{java},10190

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆