您的位置:首页 > 运维架构 > Linux

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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: