jvm线程日常状态查看

Python024

jvm线程日常状态查看,第1张

1.查看所有java进程

jps

2.查看某java进程的信息

jinfo pid

3.java堆栈跟踪工具

jstack pid

4.查看gc情况,下面命令第四位标识打印间隔,第5位为打印多少次

jstat -gcutil pid 1000 5

5.查看java进程的内存映像工具

jmap -heap pid

6.查看当前java进程堆对象统计信息

jmap -histo pid

7.出问题再使用的命令,平时别用,dump出内存情况

jmap -dump:live,format=b,file=tmp.hprof pid

8.jdk自带的反解析工具

javap -verbose TestClass

java线程的状态有下面几种状态:

/**

* Thread state for a thread which has not yet started.

*/

NEW,

/**

* Thread state for a runnable thread. A thread in the runnable

* state is executing in the Java virtual machine but it may

* be waiting for other resources from the operating system

* such as processor.

*/

RUNNABLE,

/**

* Thread state for a thread blocked waiting for a monitor lock.

* A thread in the blocked state is waiting for a monitor lock

* to enter a synchronized block/method or

* reenter a synchronized block/method after calling

* {@link Object#wait() Object.wait}.

*/

BLOCKED,

/**

* Thread state for a waiting thread.

* A thread is in the waiting state due to calling one of the

* following methods:

* <ul>

* <li>{@link Object#wait() Object.wait} with no timeout</li>

* <li>{@link #join() Thread.join} with no timeout</li>

* <li>{@link LockSupport#park() LockSupport.park}</li>

* </ul>

*

* <p>A thread in the waiting state is waiting for another thread to

* perform a particular action.

*

* For example, a thread that has called <tt>Object.wait()</tt>

* on an object is waiting for another thread to call

* <tt>Object.notify()</tt>or <tt>Object.notifyAll()</tt>on

* that object. A thread that has called <tt>Thread.join()</tt>

* is waiting for a specified thread to terminate.

*/

WAITING,

/**

* Thread state for a waiting thread with a specified waiting time.

* A thread is in the timed waiting state due to calling one of

* the following methods with a specified positive waiting time:

* <ul>

* <li>{@link #sleep Thread.sleep}</li>

* <li>{@link Object#wait(long) Object.wait} with timeout</li>

* <li>{@link #join(long) Thread.join} with timeout</li>

* <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>

* <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>

* </ul>

*/

TIMED_WAITING,

/**

* Thread state for a terminated thread.

* The thread has completed execution.

*/

TERMINATED

Windows

通过任务管理器查看进程信息

在进程页签中查看Java进程,我是idea启动,因此可以在idea下查看相关进程

此外可以在详细信息页签下Ctrl+f搜索java

通过控制台查看进程信息

进入CMD,键入tasklist,可以查看所有的进程信息,包括进程ID、内存使用情况

查看Java相关的进程,可以添加过滤条件 tasklist | findstr "java" ,需要注意windows中字符串需要使用双引号,要不就不加也是可以的

如果是在IDEA中启动程序,可以借用idea的Terminal终端执行命令

taskkill 杀死进程

杀死进程使用taskkill /pid 指定进程id,如果无法杀死,可以尝试强制杀死taskkill /pid 进程id -t -f

可以看到idea控制台中进程已结束

通过tasklist | findstr 进程id 已经无法查询到该进程,说明进程终止成功