为什么Java会产生这么多进程? [英] Why does Java spawn so many processes?

查看:313
本文介绍了为什么Java会产生这么多进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个在debian 7 vserver上运行的Java服务器应用程序。该应用程序本身可以正常运行,但是我注意到一些非常奇怪的东西。

I've written a Java server application that I run on a debian 7 vserver. The application itself workes just fine, but I notices something very strange.

在调用 java -Xmx200M -jar CCU.jar 我希望看到一个Java进程正在运行我的 CCU.jar

After calling java -Xmx200M -jar "CCU.jar I'd expect to see one Java process running my CCU.jar.

调用 top 只有一个Java进程(如预期),但是当我调用 htop 时,我得到了:

When calling top there is just one java process (as expected). But when I call htop I get this:

所有这些看起来都相同的子流程(它们具有表中显示的数据完全相同)却具有不同的PID呢?

What are all these subprocesses that seem to be the same process (they have the exactly same data showed in the table) but have different PIDs?

推荐答案

Java应用程序永远不会是单线程的(垃圾收集器线程除外),因此您总是会遇到多个线程。此外,Linux将线程实现为轻量级进程,因此,每个Java线程都将显示为具有唯一性的进程PID在 htop 中。

A java application is never single threaded (Garbage Collector thread among other). So you always end up with several thread. Moreover, Linux implement thread as Light-weight process therefore, each Java thread will appear as a process with a unique PID in htop.

这篇关于为什么Java会产生这么多进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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