20250201 jvm调优
This commit is contained in:
commit
f74e47bfef
23
src/java/jvm/JVM.java
Normal file
23
src/java/jvm/JVM.java
Normal file
@ -0,0 +1,23 @@
|
||||
package jvm;
|
||||
|
||||
public class JVM {
|
||||
|
||||
private int a;
|
||||
|
||||
private int b;
|
||||
|
||||
public JVM(int a, int b) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
public int add() {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
JVM jvm = new JVM(1, 2);
|
||||
int result = jvm.add();
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
66
src/java/jvm/heapGc.java
Normal file
66
src/java/jvm/heapGc.java
Normal file
@ -0,0 +1,66 @@
|
||||
package jvm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
|
||||
public class heapGc {
|
||||
|
||||
private byte[] bytes = new byte[1024 * 100]; // 1M
|
||||
|
||||
//cmd jvisualvm可以看到jvm的内存、线程等使用情况
|
||||
//arthas调优,https://alibaba.github.io/arthas
|
||||
public static void main(String[] args) {
|
||||
heapGc heapGc = new heapGc();
|
||||
heapGc.deadLock();
|
||||
}
|
||||
|
||||
private void gc() throws InterruptedException{
|
||||
List<heapGc> list = new ArrayList<>();
|
||||
while (true) {
|
||||
list.add(new heapGc());
|
||||
Thread.sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
private void cpuHigh(){
|
||||
new Thread(() -> {
|
||||
while (true) {
|
||||
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void deadLock(){
|
||||
Object a = new Object();
|
||||
Object b = new Object();
|
||||
Thread threadA = new Thread(() -> {
|
||||
synchronized (a) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
synchronized (b) {
|
||||
System.out.println("get b");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Thread threadB = new Thread(() -> {
|
||||
synchronized (b) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
synchronized (a) {
|
||||
System.out.println("get a");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
threadA.start();
|
||||
threadB.start();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user