2

I've checked these two posts OSX 10.6.3 and JVM support about threads limit in StackOverflow, but when I tried to test my system thread count limit using the following test, I will always get far less (like about 2000) than they mentioned in these two posts (like 40_000).

I also check this less is more about thread limit to make more local tests, but the results are still very frustrating.

F.Y.I

Using sysctl kern.num_threads to check thread limit in my mac and I got kern.num_threads: 10240

-Xmx2048m -Xms2048m -Xss200k ==> 1286
-Xmx4096m -Xms3072m -Xss320k ==> 1048
-Xmx4096m -Xms3072m          ==> 1153
-Xmx32m   -Xms32m            ==> 1309
-Xmx32m                      ==> 2027

Is there something I missed to result in this bad performance (low thread limit)?

public class TestThreadCountLimit {
    private static Object s = new Object();
    private static int count = 0;

    public static void main(String[] argv) {
        for (; ; ) {
            Thread thread = new Thread(() -> {
                synchronized (s) {
                    count += 1;
                    System.err.println("New thread #" + count);
                }
                for (; ; ) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                        System.err.println(e);
                    }
                }
            });
            thread.setDaemon(true); // to ensure I can terminate them, I set them daemon on purpose;
            thread.start();
        }
    }
}
Hearen
  • 7,420
  • 4
  • 53
  • 63
  • When I run `sysctl kern.num_threads` it returns `40960`... – l'L'l Jun 11 '18 at 03:29
  • I am using the `mac pro 2015 13-inch 8GB`, that can be the cause for the difference. But at least I should have more threads than *2000*, I think. – Hearen Jun 11 '18 at 03:32
  • This seems like a similar problem to yours... https://stackoverflow.com/questions/2860889/cant-get-past-2542-threads-in-java-on-4gb-imac-osx-10-6-3-snow-leopard-32bit – l'L'l Jun 11 '18 at 03:47
  • I mentioned it in **these two posts in my question** actually. But it seems different from my case since I got less even than that and my `kern.num_threads: 10240`. – Hearen Jun 11 '18 at 04:23
  • What is the value of `kern.num_taskthreads`? The `kern.num_threads` (10240) looks normal for your machine according to it's specs. – l'L'l Jun 11 '18 at 04:33
  • 2
    Thank you, @I'L'l. I will check it when I got back home.`kern.num_taskthreads` seems to be the root cause. – Hearen Jun 11 '18 at 04:41

0 Answers0