1. 程式人生 > >JAVA-內存及CPU排查

JAVA-內存及CPU排查

dao 頻率 executors stack 線上 object youdao pool 文件

1.現象 CPU利用率高. 應用緩慢或無法對外提供服務. 2.原因 1.死循環 2.JVM堆占用過大-高頻率FULL-GC 3.排查方法 1.使用top命令找出CPU消耗最大的進程 2.使用top -Hp 進程(上一步得到的進程號),找出消耗CPU的線程. 3.使用[jstack 進程與jstat -gcutil 進程 1000 100],找出線程在執行何種操作.. 如果線程非GC線程,則直接可以根據調用堆棧找出具體的代碼... 否則進行如下操作. 1.jstat -gcutil pid 1000 100用此命令跟蹤GC回收... 4.jmap -dump:format=b,file=memoryfile.bin 【pid】 5.sz memoryfile.bin 6.使用mat打開memoryfile.bin文件.然後分析內存.找出內存問題解決.. 4.實戰 技術分享圖片
技術分享圖片 技術分享圖片 技術分享圖片 技術分享圖片 技術分享圖片 5.線上實例 技術分享圖片 技術分享圖片 技術分享圖片 技術分享圖片 六.例子源碼 import java.util.LinkedList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class TestMemory{ //private static byte[] byteArray=new byte[1024*1024*170]; private static List<Object> linkList=new LinkedList<Object>(); private static long count=1024*1024*240/56; //private static List<Object> list=new CopyOnWriteArrayList<Object>(); public static void main(String[] args) throws Throwable{ for(int index=0;index<count;++index){ linkList.add(new Object ()); } ExecutorService service= Executors.newFixedThreadPool(5); for (int index=0;index<5;++index) { service.submit(new Runnable() { public void run() { while (true) { try { Thread.sleep(100); test(); } catch (Throwable throwable) { throwable.printStackTrace(); } } } }); } System.in.read(); } private static void test(){ byte[] bytes=new byte[1024*1024]; System.out.printf(bytes.toString()); } } public class TestProfile { private Map<TestHashCode,Object> map=new HashMap<TestHashCode,Object>(); private static Object obj=new Object(); public static void main(String[] args) throws Throwable { new TestProfile().test1(); } public void test1() throws Throwable{

JAVA-內存及CPU排查