如何启动jconsole?
方法1:找到jdk安装目录的bin文件夹,双击jconsole
方法2:win+r 输入cmd,打开dos窗口,直接输入jconsole
我们看到有两种链接方式:本地连接和远程连接。
测试代码:
/*** -Xms600m -Xmx600m -XX:SurvivorRatio=8*/
public class HeapInstanceTest {byte[] buffer = new byte[new Random().nextInt(1024 * 100)];public static void main(String[] args) {try {Thread.sleep(3000);} catch (InterruptedException e) {e.printStackTrace();}ArrayList<HeapInstanceTest> list = new ArrayList<HeapInstanceTest>();while (true) {list.add(new HeapInstanceTest());try {Thread.sleep(10);} catch (InterruptedException e) {e.printStackTrace();}}}
}
修改JVM的参数,设置堆内存大小为600m,eden和s0区、s1区比例为8:1:1
其他的我就不举例了,可以自己点点找找自己想要的信息。
/*** 演示线程的死锁问题**/
public class ThreadDeadLock {public static void main(String[] args) {StringBuilder s1 = new StringBuilder();StringBuilder s2 = new StringBuilder();new Thread(){@Overridepublic void run() {synchronized (s1){s1.append("a");s2.append("1");try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}synchronized (s2){s1.append("b");s2.append("2");System.out.println(s1);System.out.println(s2);}}}}.start();new Thread(new Runnable() {@Overridepublic void run() {synchronized (s2){s1.append("c");s2.append("3");try {Thread.sleep(100);} catch (InterruptedException e) {e.printStackTrace();}synchronized (s1){s1.append("d");s2.append("4");System.out.println(s1);System.out.println(s2);}}}}).start();}
}
远程连接:
jconsole作为一个了解即可,用起来也不费劲,jvm性能监控更推荐JVisualVM
本文发布于:2024-01-31 03:44:06,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170664385125144.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |