update for debug tools

This commit is contained in:
Jason Lu 2025-03-13 19:55:45 +08:00
parent 95e88a3ef8
commit 33b6dc149d
3 changed files with 64 additions and 1 deletions

3
.gitignore vendored
View File

@ -26,4 +26,5 @@ bin/
.vscode/
### Mac OS ###
.DS_Store
.DS_Store
/.idea/

View File

@ -0,0 +1,36 @@
package jvm.debugtool;
/**
* debug tool: Jconsole
*/
public class DeadLockDemo{
static class SyncAddRunnable implements Runnable {
int a, b;
public SyncAddRunnable(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public void run() {
synchronized (Integer.valueOf(a)) {
try {
Thread.sleep(100);
} catch ( InterruptedException e) {
e.printStackTrace();
}
synchronized (Integer.valueOf(b)) {
System.out.println(a + b);
}
}
}
}
public static void main(String[] args) {
for(int i = 0;i < 100;i++){
new Thread(new SyncAddRunnable(1,2)).start();
new Thread(new SyncAddRunnable(2,1)).start();
}
}
}

View File

@ -0,0 +1,26 @@
package jvm.debugtool;
/**
* vm args: -Xmx10m -XX:+UseSerialGC -XX:-UseCompressedOops
*/
public class JHSDBTestCase {
static class Test {
static ObjectHolder staticObj = new ObjectHolder();
ObjectHolder instanceObj = new ObjectHolder();
void foo() {
ObjectHolder localObj = new ObjectHolder();
//set break point here
System.out.println("done");
}
}
private static class ObjectHolder {}
public static void main(String[] args) {
Test test = new JHSDBTestCase.Test();
test.foo();
}
}