linux limits.conf实验
2016-07-29 18:11
477 查看
public class OOMTest {
public static void main(String[] args) throws Exception {
int threadCount = Integer.parseInt(args[0]);
try {
for (int i = 0; i < threadCount; i++) {
new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
System.out.println("Thread " + i);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
把编译的类放到linux环境
OOMTest$1.class OOMTest.class
[mysql@MySQLDB ~]$ java OOMTest 4000 -Xmx500m -Xss2m
Thread 0
.........
Thread 753
.........
Thread 3980
[root@MySQLDB ~]# vi /etc/security/limits.conf
mysql hard nproc 800
mysql soft nproc 800
重新用mysql登录一下
[mysql@MySQLDB ~]$ java OOMTest 4000 -Xmx500m -Xss2m -XX:+HeapDumpOnOutOfMemoryError
Thread 0
.........
Thread 753
Thread 754
Thread 755
Thread 756
Thread 757
Thread 758
Thread 759
Thread 760
Thread 761
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at OOMTest.main(OOMTest.java:24)
public static void main(String[] args) throws Exception {
int threadCount = Integer.parseInt(args[0]);
try {
for (int i = 0; i < threadCount; i++) {
new Thread() {
public void run() {
while (true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
System.out.println("Thread " + i);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
把编译的类放到linux环境
OOMTest$1.class OOMTest.class
[mysql@MySQLDB ~]$ java OOMTest 4000 -Xmx500m -Xss2m
Thread 0
.........
Thread 753
.........
Thread 3980
[root@MySQLDB ~]# vi /etc/security/limits.conf
mysql hard nproc 800
mysql soft nproc 800
重新用mysql登录一下
[mysql@MySQLDB ~]$ java OOMTest 4000 -Xmx500m -Xss2m -XX:+HeapDumpOnOutOfMemoryError
Thread 0
.........
Thread 753
Thread 754
Thread 755
Thread 756
Thread 757
Thread 758
Thread 759
Thread 760
Thread 761
java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at OOMTest.main(OOMTest.java:24)
相关文章推荐
- linux -- 进程的查看、进程id的获取、进程的杀死
- Linux进程调度之CFS调度器概述--Linux进程的管理与调度(二十四)
- Linux下的进程间通信-详解
- linux一些基本认识、见解或看法
- linux下Ping工具的C语言实现
- Linux syslog机制
- Linux 解除安裝 Java?
- Linux Socket编程(不限Linux)
- Linux系统中的文件目录结构介绍
- linux硬链接和软链接的区别
- linux中的rootfs/initrd/ramfs/initramfs
- 关于Linux启动时挂载rootfs的几种方式
- linux的几个内核镜像格式Image 和 u-boot启动内核和文件系统时的一些环境变量的设置
- 物理机无法连接虚拟机内Linux的解决方法
- Window下使用虚拟机Ubuntu编译Ffmpeg(编译的只有arm平台下的)
- linux常用命令笔记
- linux top命令详解
- linux 下C语言线程示例 + 线程同步
- Linux兴趣小组暑假留校第四次讲座总结
- 理解Linux系统/etc/init.d目录和/etc/rc.local脚本