How many threads can java handle




















I will let you guess the results. The test is executed on my two years old laptop with Intel Core 2 Duo T 2. There is 64bit Linux 2. Try to guess how many threads are created if I do not tinker with JVM arguments at all. Is it 1K? Or 10K? Or even more? Well, it's slightly more than 32K. Usually you see result like this. The question is, why we can not create more threads.

Are we constrained by the heap size? Or maybe stack size? No in fact, 32K is apparently Linux kernel limit. Therefore there is nothing we can do in Java, Linux is just not able to handle more threads. But I think that 32K threads is not bad at all. Please keep in mind, that you will be able to reproduce the results only on modern operating systems and JVMs. I am afraid that Windows XP results will be much worse. Please also note, that once the threads are created and all of them sleep, the application does not consume any CPU and it consumes around MB of memory.

I am not sure why so much memory is used, it has to be investigated. As we have seen, in this artificial scenario threads are relatively cheap. I do not want to say, that we should not use new libraries or tools. If you need a more precise answer than this, your safest bet is to profile. Login Sign Up. Courses Ask a Question. Please log in or register to add a comment.

Please log in or register to answer this question. Related questions. How does Naming threads and thread-pools of ExecutorService. My recommendation is to consider having more servers once your total reaches 10K.

The time it takes to create a thread increases as you create more thread. For the bit JVM, the stack size appears to limit the number of threads you can create.

This may be due to the limited address space. In any case, the memory used by each thread's stack add up. If you have a stack of KB and you have 20K threads it will use 2. Thanks for visiting DZone today,.



0コメント

  • 1000 / 1000