在4GB iMac OSX 10.6.3 Snow Leopard(32位)上无法通过Java获取2542个Threads [英] Can't get past 2542 Threads in Java on 4GB iMac OSX 10.6.3 Snow Leopard (32bit)

查看:104
本文介绍了在4GB iMac OSX 10.6.3 Snow Leopard(32位)上无法通过Java获取2542个Threads的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下程序,试图弄清楚如何配置我的JVM以获得我的机器可以支持的最大线程数。对于那些可能不知道的人,Snow Leopard附带Java 6。

I am running the following program trying to figure out how to configure my JVM to get the maximum number of threads my machine can support. For those that might not know, Snow Leopard ships with Java 6.

我尝试使用默认值启动它,以及以下命令行,我总是得到Out of Memory错误在线程2542,无论JVM选项设置为什么。

I tried starting it with defaults, and the following command lines, I always get the Out of Memory Error at Thread 2542 no matter what the JVM options are set to.

java TestThreadStackSizes 100000
java -Xss1024 TestThreadStackSizes 100000
java -Xmx128m -Xss1024 TestThreadStackSizes 100000
java -Xmx2048m -Xss1024 TestThreadStackSizes 100000
java -Xmx2048m -Xms2048m -Xss1024 TestThreadStackSizes 100000

无论我通过什么,我得到相同的结果,内存错误在2542

no matter what I pass it, I get the same results, Out of Memory Error at 2542

public class TestThreadStackSizes
{
    public static void main(final String[] args)
    {
        Thread.currentThread().setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
            public void uncaughtException(final Thread t, final Throwable e)
            {
                System.err.println(e.getMessage());
                System.exit(1);
            }
        });
        int numThreads = 1000;
        if (args.length == 1)
        {
            numThreads = Integer.parseInt(args[0]);
        }

        for (int i = 0; i < numThreads; i++)
        {
            try
            {
                Thread t = new Thread(new SleeperThread(i));
                t.start();
            }
            catch (final OutOfMemoryError e)
            {
                throw new RuntimeException(String.format("Out of Memory Error on Thread %d", i), e);
            }
        }
    }

    private static class SleeperThread implements Runnable
    {
        private final int i;

        private SleeperThread(final int i)
        {
            this.i = i;
        }

        public void run()
        {
            try
            {
                System.out.format("Thread %d about to sleep\n", this.i);
                Thread.sleep(1000 * 60 * 60);
            }
            catch (final InterruptedException e)
            {
                throw new RuntimeException(e);
            }
        }
    }
}

任意关于如何影响这些结果的想法?

Any ideas on how I can affect these results?

我写了这个程序来弄清楚Windows Server 2003的功能,因为我得到了这些内存不足无法创建本机线程,数量非常低,比如几百。我需要看一个特定的盒子能用不同的 -Xss 参数,然后我在OSX上遇到这个任意限制。

I wrote this program to figure out what a Windows Server 2003 is capable of, because I am getting these out of memory can't create native threads at very low numbers, like a couple of hundred. I need to see what a particular box was capable of with different -Xss parameters, then I run into this arbitrary limit on OSX.

推荐答案

2542似乎是一个任意数字:



我关闭了所有程序,除了我正在运行的一个终端窗口我的测试来自 2545 ,这告诉我这是一个任意限制。

2542 seems like an arbitrary number:

I shut all programs down except the one terminal window I was running my test from and I got to 2545, that told me it was an arbitrary limit.

获取数字你做的OSX 10.6.3的线程:

To get the number of threads for OSX 10.6.3 you do:

> sysctl kern.num_threads
kern.num_threads: 2560

> sysctl kern.num_taskthreads
kern.num_taskthreads: 2560

2560 数字与 2542 2545 匹配,因为显然其他线程正在运行背景。
根据官方文档 kern.num_taskthreads 无法在桌面版OSX中进行调整。

The 2560 number matches up with the 2542 and 2545 because there are obviously other threads running in the background. According to the official documentation kern.num_taskthreads can not be adjusted in the desktop version of OSX.

这篇关于在4GB iMac OSX 10.6.3 Snow Leopard(32位)上无法通过Java获取2542个Threads的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆