How many threads can a Java VM support?

前端 未结 12 1275
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 06:32

How many threads can a Java VM support? Does this vary by vendor? by operating system? other factors?

12条回答
  •  迷失自我
    2020-11-22 07:05

    After playing around with Charlie's DieLikeACode class, it looks like the Java thread stack size is a huge part of how many threads you can create.

    -Xss set java thread stack size

    For example

    java -Xss100k DieLikeADog

    But, Java has the Executor interface. I would use that, you will be able to submit thousands of Runnable tasks, and have the Executor process those tasks with a fixed number of threads.

提交回复
热议问题