ps -ef | grep java
ps -ef | grep java -c 统计java 的进程数
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class TestPS_EF {
public static void main(String[] args) {
String i = args[0];
int j = Integer.valueOf(i);
ExecutorService s = Executors.newFixedThreadPool(j);
for(int k=0;k<j;k++){
s.execute(new Runnable(){
@Override
public void run() {
System.out.println(Thread.currentThread().getName()+" start");
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(Thread.currentThread().getName()+" end");
}
});
}
s.shutdown();
}
}
运行上述代码, 再执行ps -ef | grep java -c , 进程总数加一。
ehanmqi 45556 45519 1 2015 pts/17 05:51:48 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/bin/java -Xms128m -Xmx1024m -Dsoapui.properties=soapui.properties -Dsoapui.home=/root/PGCATemp/SoapUI-5.0.0/bin -splash:soapui-splash.png -Dsoapui.ext.libraries=/root/PGCATemp/SoapUI-5.0.0/bin/ext -Dsoapui.ext.listeners=/root/PGCATemp/SoapUI-5.0.0/bin/listeners -Dsoapui.ext.actions=/root/PGCATemp/SoapUI-5.0.0/bin/actions -Djava.library.path=/root/PGCATemp/SoapUI-5.0.0/bin -Dwsi.dir=/root/PGCATemp/SoapUI-5.0.0/wsi-test-tools -cp /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre/lib/jfxrt.jar:/root/PGCATemp/SoapUI-5.0.0/bin/soapui-5.0.0.jar:/root/PGCATemp/SoapUI-5.0.0/lib/* com.eviware.soapui.SoapUI
[root@dallas02 ~]# ps 45519
PID TTY STAT TIME COMMAND
45519 pts/17 S+ 0:00 /bin/sh ./soapui_1.sh
[root@dallas02 ~]# ps 45556
PID TTY STAT TIME COMMAND
45556 pts/17 Sl+ 351:50 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/bin/java -Xms128m -Xmx1024m -Dsoapui.properties=soapui.properties -Dsoapui.home=/root/PGCATemp
[root@dallas02 ~]#
要让top输出某个特定进程<pid>并检查该进程内运行的线程状况:
$ top -H -p <pid>
root 15152 12835 1 12:26 pts/129 00:00:00 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/bin/java TestPS_EF2 10
[root@dallas02 ~]# /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/bin/jstack 15152
2016-01-15 12:26:33
Full thread dump OpenJDK 64-Bit Server VM (23.2-b09 mixed mode):
"Attach Listener" daemon prio=10 tid=0x00007f17f4001000 nid=0x3b9c waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"DestroyJavaVM" prio=10 tid=0x00007f1898008000 nid=0x3b31 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Thread-9" prio=10 tid=0x00007f189817c000 nid=0x3b71 waiting on condition [0x00007f18428e7000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-8" prio=10 tid=0x00007f189817a000 nid=0x3b70 waiting on condition [0x00007f18429e8000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-7" prio=10 tid=0x00007f1898178000 nid=0x3b6f waiting on condition [0x00007f1842ae9000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-6" prio=10 tid=0x00007f1898176000 nid=0x3b6d waiting on condition [0x00007f1842bea000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-5" prio=10 tid=0x00007f1898174000 nid=0x3b6b waiting on condition [0x00007f1842ceb000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-4" prio=10 tid=0x00007f1898172000 nid=0x3b69 waiting on condition [0x00007f1842dec000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-3" prio=10 tid=0x00007f1898170000 nid=0x3b68 waiting on condition [0x00007f1842eed000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-2" prio=10 tid=0x00007f189816d800 nid=0x3b64 waiting on condition [0x00007f1842fee000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-1" prio=10 tid=0x00007f189816b800 nid=0x3b63 waiting on condition [0x00007f18430ef000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Thread-0" prio=10 tid=0x00007f189816a000 nid=0x3b62 waiting on condition [0x00007f18431f0000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at TestPS_EF2$1.run(TestPS_EF2.java:14)
at java.lang.Thread.run(Thread.java:722)
"Service Thread" daemon prio=10 tid=0x00007f1898135800 nid=0x3b59 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread1" daemon prio=10 tid=0x00007f1898133000 nid=0x3b58 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"C2 CompilerThread0" daemon prio=10 tid=0x00007f1898130000 nid=0x3b57 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher" daemon prio=10 tid=0x00007f189812e000 nid=0x3b55 runnable [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
"Finalizer" daemon prio=10 tid=0x00007f18980d8800 nid=0x3b54 in Object.wait() [0x00007f18437f6000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000006b0ab5728> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
- locked <0x00000006b0ab5728> (a java.lang.ref.ReferenceQueue$Lock)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:177)
"Reference Handler" daemon prio=10 tid=0x00007f18980d6000 nid=0x3b53 in Object.wait() [0x00007f18438f7000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x00000006b0ab52b0> (a java.lang.ref.Reference$Lock)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
- locked <0x00000006b0ab52b0> (a java.lang.ref.Reference$Lock)
"VM Thread" prio=10 tid=0x00007f18980cd800 nid=0x3b52 runnable
"GC task thread#0 (ParallelGC)" prio=10 tid=0x00007f1898015800 nid=0x3b32 runnable
"GC task thread#1 (ParallelGC)" prio=10 tid=0x00007f1898017800 nid=0x3b33 runnable
"GC task thread#2 (ParallelGC)" prio=10 tid=0x00007f1898019800 nid=0x3b34 runnable
"GC task thread#3 (ParallelGC)" prio=10 tid=0x00007f189801b000 nid=0x3b36 runnable
"GC task thread#4 (ParallelGC)" prio=10 tid=0x00007f189801d000 nid=0x3b38 runnable
"GC task thread#5 (ParallelGC)" prio=10 tid=0x00007f189801f000 nid=0x3b39 runnable
"GC task thread#6 (ParallelGC)" prio=10 tid=0x00007f1898020800 nid=0x3b3a runnable
"GC task thread#7 (ParallelGC)" prio=10 tid=0x00007f1898022800 nid=0x3b3b runnable
"GC task thread#8 (ParallelGC)" prio=10 tid=0x00007f1898024800 nid=0x3b41 runnable
"GC task thread#9 (ParallelGC)" prio=10 tid=0x00007f1898026000 nid=0x3b43 runnable
"GC task thread#10 (ParallelGC)" prio=10 tid=0x00007f1898028000 nid=0x3b45 runnable
"GC task thread#11 (ParallelGC)" prio=10 tid=0x00007f189802a000 nid=0x3b46 runnable
"GC task thread#12 (ParallelGC)" prio=10 tid=0x00007f189802c000 nid=0x3b47 runnable
"GC task thread#13 (ParallelGC)" prio=10 tid=0x00007f189802d800 nid=0x3b48 runnable
"GC task thread#14 (ParallelGC)" prio=10 tid=0x00007f189802f800 nid=0x3b49 runnable
"GC task thread#15 (ParallelGC)" prio=10 tid=0x00007f1898031800 nid=0x3b4a runnable
"GC task thread#16 (ParallelGC)" prio=10 tid=0x00007f1898033000 nid=0x3b4b runnable
"GC task thread#17 (ParallelGC)" prio=10 tid=0x00007f1898035000 nid=0x3b4c runnable
"GC task thread#18 (ParallelGC)" prio=10 tid=0x00007f1898037000 nid=0x3b4d runnable
"GC task thread#19 (ParallelGC)" prio=10 tid=0x00007f1898038800 nid=0x3b4e runnable
"GC task thread#20 (ParallelGC)" prio=10 tid=0x00007f189803a800 nid=0x3b4f runnable
"GC task thread#21 (ParallelGC)" prio=10 tid=0x00007f189803c800 nid=0x3b50 runnable
"GC task thread#22 (ParallelGC)" prio=10 tid=0x00007f189803e000 nid=0x3b51 runnable
"VM Periodic Task Thread" prio=10 tid=0x00007f1898140000 nid=0x3b5f waiting on condition
JNI global references: 109
[root@dallas02 ~]#
分享到:
相关推荐
- `jps`(Java Virtual Machine Process Status Tool)是JDK自带的工具,用于查看Java进程的ID。例如,`jps` 可以显示运行的Java应用程序的进程ID。 3. **`top` 命令**: - `top` 提供了一个实时的视图,显示了...
功能:获取java进程pid 进程可根据该pid调用exec自杀 注意事项:不能改变PidTool.java所在的包,否则需要重行生成dll。 编译命令中 "-PidTool.dll" 改为 "-FePidTool.dll",我整漏了! 使用方法: 1.javac PidTool...
可以使用`jstack`命令来查看Java进程的线程堆栈,找出可能的阻塞点或热点线程。此外,`VisualVM`或`JProfiler`等工具也可以帮助分析线程状态,识别是否有死锁、线程饥饿等问题。 **垃圾收集优化** Java的自动内存...
### Windows系统下启动与结束Java的JAR包的脚本(包括如何设置进程名称) 在Windows环境下管理和控制Java应用程序的启动与停止是一项常见的任务。本文将详细介绍如何编写一个批处理脚本来实现这些功能,并且还会...
JAVA进程占用高内存缘由分析与优化方法 在 Java 进程中,高内存占用是一个常见的问题,本文将通过 jmap 和 ps 命令来分析 Java 进程的内存占用情况,并讨论可能的优化方法。 1. Java 进程的内存占用分析 使用 ...
Linux查看处理Java进程
`bin`目录可能包含编译后的可执行文件或脚本,用于启动和管理这些Java进程。为了深入了解实现细节,需要查看源代码并理解其逻辑。 总的来说,Java实现守护进程、监听进程以及管理多个进程和JVM涉及多线程、网络编程...
本人写了一个java进程通信的工具jar,方便大家简单的使用java进程通信。 开启守护进程,获取消息: package com.test; import org.msun.process.ProcessMonitor; import org.msun.process.ProcessMonitor....
### Java通过进程名称杀进程 在日常开发与运维过程中,我们常常需要对系统中的特定进程进行管理和控制。本文将详细介绍如何使用Java代码实现基于进程名称的进程终止功能,特别是针对Windows操作系统下的`java-test....
Java VisualVM 是一个 Java 可视化工具,用于查看 Java 进程中的线程信息、堆内存使用情况、GC 情况等信息。使用 Java VisualVM 工具可以查看 Java 进程中的线程 Dump 信息。 Thread Dump 的内容 Thread Dump ...
2. 查看Java进程详细信息:`jps` 命令可以查看Java进程详细信息。 3. 查看Java堆栈信息:`jstack` 命令可以查看Java堆栈信息。 4. 查看Java内存信息:`jmap` 命令可以查看Java内存信息。 5. 查看Java垃圾回收信息:`...
Java进程调度算法模拟是计算机科学中的一个重要概念,特别是在多任务操作系统和并发编程中。这个话题源于操作系统原理,但在Java环境中,我们可以通过编程实现对进程调度的模拟,以便理解和掌握不同的调度策略。在这...
Java进程间的管道通信是一种进程间通信(IPC,Inter-Process Communication)的方式,它允许不同的Java进程之间通过共享的管道进行数据传输。虽然Java标准库不直接支持创建管道文件,但可以借助于操作系统提供的功能...
java进程间通讯机制代码----RMI、共享内存、Socket、管道,等方式,每种方法我都讲了原理和例子程序,很有参考意义。在网上很难找到的。
本项目“JAVA进程管理模拟”旨在通过一个图形用户界面(GUI)来直观地展示进程优先级如何影响进程的执行顺序和资源分配。下面我们将深入探讨相关知识点。 首先,我们来理解“进程”。在操作系统中,进程是程序的一...
这些文件的代码分析可以帮助进一步理解Java进程管理的实践应用。 总结来说,Java提供了一套机制来创建和管理进程,但直接根据命令行参数或PID删除进程则需要借助操作系统特定的工具或API。理解和掌握这些概念对于...
java进程方法栈分析方法。可以找到导致服务器负载高的线程的相应代码。
本项目名为"java进程项目",显然与Java程序的运行和管理有关,特别是涉及到使用Maven进行构建以及项目的部署过程。下面将详细介绍相关知识点。 **Java进程** Java进程是指在操作系统中运行的Java应用程序实例,每个...
NULL 博文链接:https://skly-java.iteye.com/blog/1745968
java进程间通讯机制代码 RMI(Remote Method Invocation)是一种基于Java的分布式编程模型,为java程序提供远程访问服务接口。