標籤: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排查