用简单的Java代码创建的这些JVM守护程序线程是什么? [英] What are these JVM daemon threads created in simple java code?

查看:79
本文介绍了用简单的Java代码创建的这些JVM守护程序线程是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Java应用程序,它只是创建一个对象,并在无限循环内对其调用所有函数

I have so simple java app, It simply creates an object, calls a function on it all these inside an infinite loop

public class h { 
    public static void main( String[] args) {
        while(true) {
            B b = new B();
            b.print();
        }
    }
}

class B { 
    public void print() {
        System.out.println("Hello I'am class B");
    }
}

打开jvisualvm,我看到JVM创建了10个线程,只有一个活动线程(即主线程)和9个守护程序.

Opening the jvisualvm I see 10 threads created by the JVM, only one active which is the main thread and 9 daemons.

这9个线程的用途是什么?

What is the usage of these 9 threads ?

并且其中有人与垃圾收集有任何关系吗?

And is anyone of them related to Garabage collection in any manner ?

注意: java -version的输出:

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)

OS:Arch Linux 4.8.6-1

OS : Arch Linux 4.8.6-1

推荐答案

  • Signal Dispatcher 等待特定的OS信号并处理它们.特别是,它会在SIGQUIT上进行线程转储,并在SIGTERMSIGINTSIGHUP上启动VM关闭过程.
  • Attach Listener 线程支持动态附加机制.它侦听传入的动态附加连接并执行VM命令.例如,jstackjmapjcmd实用程序使用它.
  • RMI TCP Accept线程显然接受新的RMI连接.
  • RMI TCP Connection线程服务已建立的RMI连接.
  • RMI Scheduler运行RMI后台任务,例如 DGC .
  • JMX server connection timeout线程在需要时终止JMX连接.
    • Reference Handler thread is responsible for adding Weak, Soft and Phantom references discovered by Garbage Collector into their registered ReferenceQueues.
    • Finalizer thread runs finalize method of the objects ready to be finalized.
    • Signal Dispatcher waits for specific OS signals and handles them. In particular, it makes thread dump on SIGQUIT, and also initiates VM shutdown process on SIGTERM, SIGINT, SIGHUP.
    • Attach Listener thread supports Dynamic Attach mechanism. It listens for incoming Dynamic Attach connections and executes VM commands. For example, it is used by jstack, jmap and jcmd utilities.
    • RMI TCP Accept thread obviously accepts new RMI connections.
    • RMI TCP Connection threads serve the established RMI connections.
    • RMI Scheduler runs RMI background tasks like DGC.
    • JMX server connection timeout thread terminates JMX connetion when needed.
    • Reference HandlerFinalizer和部分RMI Scheduler与GC相关.

      Reference Handler, Finalizer and partly RMI Scheduler are related to GC.

      这篇关于用简单的Java代码创建的这些JVM守护程序线程是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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