JAVA-記憶體及CPU排查

來源:互聯網
上載者:User

標籤:byte   問題   sub   str   string   youdao   rgs   []   tac   

1.現象CPU利用率高.應用緩慢或無法對外提供服務.2.原因1.死迴圈2.JVM堆佔用過大-高頻率FULL-GC3.排查方法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.bin6.使用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排查

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.