0%

JavaOOM

image-20200727151343863

StackOverFlowError

1
2
3
4
5
6
7
8
9
10
public class StackOverFlowErrorDemo {

public static void main(String[] args) {
dfs();//Exception in thread "main" java.lang.StackOverflowError
}

public static void dfs(){
dfs();
}
}

最常见在递归中无返回条件一直调用。

JavaHeapSpace

1
2
3
4
5
6
7
8
9
10
11
public class JavaHeapSpaceDemo {

public static void main(String[] args) {
String str="wqoierihfsdkfsdf";

while (true){
str+=new Random().nextInt(108432432)+new Random().nextInt(238923293);
str.intern();
}
}
}

image-20200727152702974

GC Overhead Limited Exceeded

image-20200727153202737

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**-Xms10m -Xmx10m -XX:+PrintGCDetails -XX:MaxDirectMemorySize=3m
* @author xixing
* @version 1.0
* @date 2020/7/27 15:33
*/
public class GCOverheadDemo {

public static void main(String[] args) {
int i=0;

List<String> list=new ArrayList<>();

try {
while (true){
list.add(String.valueOf(i++).intern());
}
}catch (Throwable e){

System.out.println("********************");
System.out.println(i);
e.printStackTrace();

}
}
}

DirectBufferMemory

image-20200727155332807

image-20200727155352610

1
2
3
4
5
6
7
8
9
10
11
12
13
/**
* @author xixing
* @version 1.0
* @date 2020/7/27 15:49
*/
public class DirectBufferMemoryDemo {
public static void main(String[] args) {


System.out.println("配置的本地内存maxDirectMemory:"+sun.misc.VM.maxDirectMemory()/(double)1024/1024+"MB");
Buffer bb= ByteBuffer.allocateDirect(10*1024*1024);
}
}

Unable to create new native thread

image-20200727160305811

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* @author xixing
* @version 1.0
* @date 2020/7/27 16:08
*/
public class UnableCreateNewThreadDemo {
public static void main(String[] args) {

for (int i = 0; ; i++) {
System.out.println("****************"+i);
new Thread(()->{
try {
Thread.sleep(Integer.MAX_VALUE);
} catch (InterruptedException e) {
e.printStackTrace();
}
},String.valueOf(i)).start();
}

}
}

调整最大线程数

ulimit -u 查看可以创建的最大线程

vim /etc/security/limits.d/90-nproc.conf

Metaspace

image-20200727162251944

image-20200727162956731