linux 查看java线程与linux线程关系

news2025/1/23 6:22:44

linux 查看占用cpu高的 java 线程

linux 排查cpu占用100%故障

##java程序

import java.util.Scanner;
public class JavaThreadIDName {

    public static void main(String[] args) {
        Thread t = Thread.currentThread();
        t.setName("laoyoutiao");
        System.out.println("Thread ID: " + t.getId());
        System.out.println("Thread Name: " + t.getName());
        Scanner scanner = new Scanner(System.in);
        String inputString = scanner.nextLine(); // 等待用户输入一行文本
        System.out.println("你输入的是: " + inputString);
    }

}

##linux查看java进程

jps
11409 Jps
10133 JavaThreadIDName

##linux查看java进程最耗cpu资源java线程

top -H -bn 1 -p 10133
top - 18:54:21 up  1:21,  1 user,  load average: 0.09, 0.38, 0.26
Threads:  17 total,   0 running,  17 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.0 us,  0.3 sy,  0.1 ni, 98.3 id,  0.2 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem : 16424100 total,  9156748 free,  3143220 used,  4124132 buff/cache
KiB Swap:   998396 total,   998396 free,        0 used. 12839668 avail Mem 

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
10133 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 java
10134 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:01.06 laoyoutiao
10135 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 GC Thread#0
10136 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 G1 Main Marker
10137 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 G1 Conc#0
10138 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 G1 Refine#0
10139 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.02 G1 Young RemSet
10140 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.01 VM Thread
10141 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Reference Handl
10142 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Finalizer
10143 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Signal Dispatch
10144 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Service Thread
10145 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.37 C2 CompilerThre
10146 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.76 C1 CompilerThre
10147 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Sweeper thread
10148 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.00 Common-Cleaner
10151 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:00.10 VM Periodic Tas

##linux查看java线程

ps -T -p  10133
  PID  SPID TTY          TIME CMD
10133 10133 pts/19   00:00:00 java
10133 10134 pts/19   00:00:01 laoyoutiao
10133 10135 pts/19   00:00:00 GC Thread#0
10133 10136 pts/19   00:00:00 G1 Main Marker
10133 10137 pts/19   00:00:00 G1 Conc#0
10133 10138 pts/19   00:00:00 G1 Refine#0
10133 10139 pts/19   00:00:02 G1 Young RemSet
10133 10140 pts/19   00:00:01 VM Thread
10133 10141 pts/19   00:00:00 Reference Handl
10133 10142 pts/19   00:00:00 Finalizer
10133 10143 pts/19   00:00:00 Signal Dispatch
10133 10144 pts/19   00:00:00 Service Thread
10133 10145 pts/19   00:00:00 C2 CompilerThre
10133 10146 pts/19   00:00:00 C1 CompilerThre
10133 10147 pts/19   00:00:00 Sweeper thread
10133 10148 pts/19   00:00:00 Common-Cleaner
10133 10151 pts/19   00:00:09 VM Periodic Tas

##linux查看java堆栈

jstack 10133
2024-05-16 09:31:15
Full thread dump OpenJDK 64-Bit Server VM (11.0.21-internal+0-adhoc.yym.jdk11u-master mixed mode):

Threads class SMR info:
_java_thread_list=0x00007f83c40021f0, length=10, elements={
0x00007f8408031800, 0x00007f8408312000, 0x00007f8408315000, 0x00007f8408350000,
0x00007f8408352800, 0x00007f8408355000, 0x00007f8408357800, 0x00007f840835a000,
0x00007f84083af800, 0x00007f83c4001000
}
_java_thread_list_alloc_cnt=15, _java_thread_list_free_cnt=14, _java_thread_list_max=11, _nested_thread_list_max=0
_tlh_cnt=55480, _tlh_times=3, avg_tlh_time=0.00, _tlh_time_max=1
_deleted_thread_cnt=2, _deleted_thread_times=0, avg_deleted_thread_time=0.00, _deleted_thread_time_max=0
_delete_lock_wait_cnt=0, _delete_lock_wait_max=0
_to_delete_list_cnt=0, _to_delete_list_max=1

"laoyoutiao" #1 prio=5 os_prio=0 cpu=1062.77ms elapsed=52744.36s tid=0x00007f8408031800 nid=0x2796 runnable  [0x00007f8411459000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_in_native
Thread: 0x00007f8408031800  [0x2796] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_in_native
	at java.io.FileInputStream.readBytes(java.base/Native Method)
	at java.io.FileInputStream.read(java.base/FileInputStream.java:279)
	at java.io.BufferedInputStream.read1(java.base/BufferedInputStream.java:290)
	at java.io.BufferedInputStream.read(java.base/BufferedInputStream.java:351)
	- locked <0x000000071510dfa8> (a java.io.BufferedInputStream)
	at sun.nio.cs.StreamDecoder.readBytes(java.base/StreamDecoder.java:284)
	at sun.nio.cs.StreamDecoder.implRead(java.base/StreamDecoder.java:326)
	at sun.nio.cs.StreamDecoder.read(java.base/StreamDecoder.java:178)
	- locked <0x0000000714916f58> (a java.io.InputStreamReader)
	at java.io.InputStreamReader.read(java.base/InputStreamReader.java:181)
	at java.io.Reader.read(java.base/Reader.java:189)
	at java.util.Scanner.readInput(java.base/Scanner.java:882)
	at java.util.Scanner.findWithinHorizon(java.base/Scanner.java:1796)
	at java.util.Scanner.nextLine(java.base/Scanner.java:1649)
	at JavaThreadIDName.main(JavaThreadIDName.java:10)

"Reference Handler" #2 daemon prio=10 os_prio=0 cpu=0.22ms elapsed=52744.24s tid=0x00007f8408312000 nid=0x279d waiting on condition  [0x00007f83e844a000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f8408312000  [0x279d] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked
	at java.lang.ref.Reference.waitForReferencePendingList(java.base/Native Method)
	at java.lang.ref.Reference.processPendingReferences(java.base/Reference.java:241)
	at java.lang.ref.Reference$ReferenceHandler.run(java.base/Reference.java:213)

"Finalizer" #3 daemon prio=8 os_prio=0 cpu=1.21ms elapsed=52744.24s tid=0x00007f8408315000 nid=0x279e in Object.wait()  [0x00007f83e8349000]
   java.lang.Thread.State: WAITING (on object monitor)
   JavaThread state: _thread_blocked
Thread: 0x00007f8408315000  [0x279e] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked
	at java.lang.Object.wait(java.base/Native Method)
	- waiting on <0x0000000715109008> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base/ReferenceQueue.java:155)
	- waiting to re-lock in wait() <0x0000000715109008> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base/ReferenceQueue.java:176)
	at java.lang.ref.Finalizer$FinalizerThread.run(java.base/Finalizer.java:170)

"Signal Dispatcher" #4 daemon prio=9 os_prio=0 cpu=0.54ms elapsed=52744.17s tid=0x00007f8408350000 nid=0x279f runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f8408350000  [0x279f] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked

"Service Thread" #5 daemon prio=9 os_prio=0 cpu=0.05ms elapsed=52744.17s tid=0x00007f8408352800 nid=0x27a0 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f8408352800  [0x27a0] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked

"C2 CompilerThread0" #6 daemon prio=9 os_prio=0 cpu=456.01ms elapsed=52744.17s tid=0x00007f8408355000 nid=0x27a1 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f8408355000  [0x27a1] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked
   No compile task

"C1 CompilerThread0" #9 daemon prio=9 os_prio=0 cpu=865.46ms elapsed=52744.17s tid=0x00007f8408357800 nid=0x27a2 waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f8408357800  [0x27a2] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked
   No compile task

"Sweeper thread" #10 daemon prio=9 os_prio=0 cpu=0.04ms elapsed=52744.17s tid=0x00007f840835a000 nid=0x27a3 runnable  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f840835a000  [0x27a3] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked

"Common-Cleaner" #11 daemon prio=8 os_prio=0 cpu=24.27ms elapsed=52744.12s tid=0x00007f84083af800 nid=0x27a4 in Object.wait()  [0x00007f83cb3fa000]
   java.lang.Thread.State: TIMED_WAITING (on object monitor)
   JavaThread state: _thread_blocked
Thread: 0x00007f84083af800  [0x27a4] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked
	at java.lang.Object.wait(java.base/Native Method)
	- waiting on <0x0000000715128de8> (a java.lang.ref.ReferenceQueue$Lock)
	at java.lang.ref.ReferenceQueue.remove(java.base/ReferenceQueue.java:155)
	- waiting to re-lock in wait() <0x0000000715128de8> (a java.lang.ref.ReferenceQueue$Lock)
	at jdk.internal.ref.CleanerImpl.run(java.base/CleanerImpl.java:148)
	at java.lang.Thread.run(java.base/Thread.java:829)
	at jdk.internal.misc.InnocuousThread.run(java.base/InnocuousThread.java:161)

"Attach Listener" #12 daemon prio=9 os_prio=0 cpu=0.15ms elapsed=0.21s tid=0x00007f83c4001000 nid=0x2cca waiting on condition  [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE
   JavaThread state: _thread_blocked
Thread: 0x00007f83c4001000  [0x2cca] State: _at_safepoint _has_called_back 0 _at_poll_safepoint 0
   JavaThread state: _thread_blocked

"VM Thread" os_prio=0 cpu=1264.74ms elapsed=52744.28s tid=0x00007f84082fb800 nid=0x279c runnable  

"GC Thread#0" os_prio=0 cpu=569.98ms elapsed=52744.36s tid=0x00007f8408051000 nid=0x2797 runnable  

"G1 Main Marker" os_prio=0 cpu=4.53ms elapsed=52744.35s tid=0x00007f84080b1800 nid=0x2798 runnable  

"G1 Conc#0" os_prio=0 cpu=0.03ms elapsed=52744.35s tid=0x00007f84080b3800 nid=0x2799 runnable  

"G1 Refine#0" os_prio=0 cpu=4.80ms elapsed=52744.35s tid=0x00007f84081d9800 nid=0x279a runnable  

"G1 Young RemSet Sampling" os_prio=0 cpu=2482.68ms elapsed=52744.35s tid=0x00007f84081db800 nid=0x279b runnable  
"VM Periodic Task Thread" os_prio=0 cpu=10019.83ms elapsed=52743.55s tid=0x00007f84086ba000 nid=0x27a7 waiting on condition  

JNI global refs: 9, weak refs: 0

##

ps显示pid和java nid 计算。可以使用计算器转换16进制

10134 yym       20   0 6895436  98148  28224 S  0.0  0.6   0:01.06 laoyoutiao

"laoyoutiao" #1 prio=5 os_prio=0 cpu=1062.77ms elapsed=52744.36s tid=0x00007f8408031800 nid=0x2796 runnable  [0x00007f8411459000]

由此就可以查看哪个java线程最耗cpu资源。从而解决cpu 100%问题。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1681505.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

环保科普馆如何互动化加深观众环保认知?

如今&#xff0c;多媒体技术的广泛应用&#xff0c;已经为环保、天文、生物等各类主题展厅注入了新的活力&#xff0c;在这些展馆中&#xff0c;它凭借独特的互动体验&#xff0c;以及深入浅出的教育方式&#xff0c;赢得了广大观众的热烈追捧。今天&#xff0c;我们就一同探讨…

绘唐2跟绘唐3有什么区别

绘唐2跟绘唐3有什么区别 这款产品的最大亮点在于其高度精准的语音克隆能力&#xff0c;利用先进的模型&#xff0c;能够捕捉到用户独特的音调、音高和调制方式&#xff0c;使用户能够以前所未有的方式复制和利用自己的声音。仅需10秒钟的录制时间&#xff0c;即可实现声音的克…

spring-boot-starter-mail 定义邮件工具类EmailHelper

注意 想把这个工具类定义成工具类&#xff0c;所以所有的方法都是静态方法&#xff0c;使用的变量处理参数理所当然都是静态变量期初使用的是Autowired 和 Value进行注解&#xff0c;但是这两个注解是依赖于实例&#xff0c;静态方法是不依赖实例的&#xff0c;所以 from 在发送…

24年5月GPT-4o使用教程,一看就会(低配贾维斯?)

一、 GPT-4o 5月13日&#xff0c;GPT-4o发布&#xff0c;听说是低配钢铁侠的贾维斯&#xff1f;赶紧看一下~ 二、什么是GPT-4o GPT-4o&#xff08;“o”代表“omni”&#xff09;是迈向更自然的人机交互的一步——它接受文本、音频、图像和视频的任意组合作为输入&#xff0…

Microsoft Dataverse中的安全概念

Dataverse的一个关键特性是其丰富的安全模型&#xff0c;可以适应许多业务使用场景。只有当环境中存在Dataverse数据库时&#xff0c;此安全模型才会发挥作用。作为管理员&#xff0c;您可能不会自己构建整个安全模型&#xff0c;但通常会参与管理用户、确保他们拥有正确的配置…

OpenAI 最近发布的 GPT-4o 模型,作为其自然语言处理技术的最新突破,标志着人工智能领域的一个新纪元。

2024年5月14日&#xff0c;OpenAI推出了其最新的旗舰模型——**GPT-4o**。不同于传统的AI搜索引擎或预期中的GPT-5&#xff0c;GPT-4o在功能上取得了重大突破&#xff0c;将文本、视觉和音频理解融合在一个模型中。让我们深入了解这一革命性的AI。 “o”代表什么&#xff1f; …

案例实践 | 招商局集团基于长安链的双循环航运贸易应用

案例名称-招商局双循环航运贸易联盟链 ■ 建设单位 招商局集团 ■ 用户群体 货主企业、物流企业、基础设施运营商等各参与主体 ■ 应用成效 已赋能产业链上下游超1.2万家中小微企业&#xff0c;累计提供普惠金融超830亿元 案例背景 作为全球贸易大国&#xff0c;我国约…

使用numpy或pytorch校验两个张量是否相等

文章目录 1、numpy2、pytorch 做算法过程中&#xff0c;如果涉及到模型落地&#xff0c;那必然会将原始的深度学习的框架训练好的模型转换成目标硬件模型的格式&#xff0c;如onnx,tensorrt,openvino,tflite;那么就有对比不同格式模型输出的一致性&#xff0c;从而判断模型转换…

【LeetCode:23. 合并 K 个升序链表 + 链表 + 归并 + 递归】

&#x1f680; 算法题 &#x1f680; &#x1f332; 算法刷题专栏 | 面试必备算法 | 面试高频算法 &#x1f340; &#x1f332; 越难的东西,越要努力坚持&#xff0c;因为它具有很高的价值&#xff0c;算法就是这样✨ &#x1f332; 作者简介&#xff1a;硕风和炜&#xff0c;…

Linux上编译安装和卸载软件

在maven官网下载maven时候&#xff0c;看到maven-3.9.5这个版本有2份安装包&#xff0c;一个是binaries&#xff0c;一个是source binaries是已编译好的文件&#xff0c;可以直接使用的版本&#xff1b;source是源代码版本&#xff0c;需要自己编译 源码的安装一般由这三个步…

齐护K210系列教程(二十七)_语音识别

语音识别 1.烧录固件和模型2.语音识别程序2.1训练并识别2.2使用本地文件语音识别 3.课程资源联系我们 1.烧录固件和模型 注&#xff1a;本应用只适用于有麦克风功能的型号&#xff1a;AIstart_pro、AIstart_掌机、AIstart_Mini, 其它型号不支持&#xff01; 机器码生成以及模…

集成了Gemini的Android Studio,如虎添翼

今天将Android Studio升级到最新版&#xff08;Jellyfish&#xff09;。发现在new features中有一条&#xff1a; Code suggestions with Gemini in Android Studio 打开路径为&#xff1a; View > Tool Windows > Gemini 支持多国语言&#xff0c;英文、中文都能正确理解…

网络安全人士必知的人工智能对抗模型MITRE ATLAS

图片由通义万相绘制 MITRE ATLAS™&#xff08;人工智能系统的对抗威胁格局&#xff09;是一个关于机器学习 (ML) 系统的对手战术、技术和案例研究的知识库&#xff0c;基于现实世界的观察、ML红队和安全小组的演示&#xff0c;以及学术研究的可能性状态。ATLAS 是仿照MITRE A…

ssm132医院住院综合服务管理系统设计与开发+vue

医院住院综合服务管理系统的设计与实现 摘 要 互联网发展至今&#xff0c;无论是其理论还是技术都已经成熟&#xff0c;而且它广泛参与在社会中的方方面面。它让信息都可以通过网络传播&#xff0c;搭配信息管理工具可以很好地为人们提供服务。针对医院住院信息管理混乱&…

【御控物联】物联网协议

文章目录 一、前言二、协议清单三、技术资料 一、前言 如果一个人想要和全球各个国家贸易&#xff0c;那这个人就得懂各个国家的语言或者全球通用语言&#xff0c;同样&#xff0c;在物联网的世界里&#xff0c;各家设备也都拥有自己的语言&#xff08;协议&#xff09;&#…

Edwards爱德华PHM3000培训PPT课件内容可见图片详情

Edwards爱德华PHM3000培训PPT课件内容可见图片详情

Spring初学入门(跟学笔记)

一、Spring概述 Spring是一款主流的Java EE轻量级开源框架。 Spring的核心模块&#xff1a;IoC&#xff08;控制反转&#xff0c;指把创建对象过程交给Spring管理 &#xff09;、AOP&#xff08;面向切面编程&#xff0c;在不修改源代码的基础上增强代码功能&#xff09; 二、…

JavaWeb--18 tlias-web-management 登录认证

登录认证 1 登录功能功能开发 2 登录校验2.1 问题分析2.2 会话技术CookieSession令牌技术 2.3 JWT令牌介绍生成和校验登录下发令牌 2.4 过滤器Filter拦截路径过滤器链 登录校验-Filter 2.5 拦截器InterceptorInterceptor详解执行流程 登录校验- Interceptor 3 异常处理3.1 当前…

网页封装App技术详解与小猪APP分发解决方案

移动互联网的浪潮中&#xff0c;网页封装App&#xff08;又称Hybrid App&#xff09;以其快速部署、成本效益高的特点&#xff0c;成为众多企业和开发者的选择。这种技术允许开发者将网页内容封装进原生App外壳&#xff0c;从而在不牺牲用户体验的前提下&#xff0c;实现跨平台…

常用五款文件加密软件|好用加密软件工具分享

随着信息化时代的到来&#xff0c;数据安全问题日益凸显&#xff0c;加密软件应运而生&#xff0c;成为了保护数据安全的重要手段。在市场上&#xff0c;众多加密软件层出不穷&#xff0c;各有千秋。本文将介绍几款常用的加密软件&#xff0c;分析它们的优缺点&#xff0c;以帮…