Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

java - Maximum number of threads in a JVM?

What are the maximum number of threads which can be maintained by the Java virtual machine?

I did not explain this in my original question, but I am trying to benchmark the JVM and would like to try and see how many threads it can concurrently maintain.

Creating threads in a loop until an exception is thrown is an option, however, I would like to know if there is a better way to do this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There will be some limits imposed by your operating system and hardware configuration.

To raise the number of concurrent threads you should lower the default stacksize java -Xss 64k.

  • A Oracle 32 bit JVM will default to 320kb stack size per thread.
    • For a 32 bit JVM with 2gb of addressable memory this will give you a maximum of 6.5k threads.
  • A Oracle 64 bit JVM will default to 1M stack size per thread.
    • For each gigabyte of memory you would get 1024 threads using the defaults.
  • For Linux only:
    • ulimit -a will give you the configured limits, for user processes and memory
    • You will only get 32k unique PIDs in linux cat /proc/sys/kernel/pid_max - a maximum of 32k processes.
    • You will get only 255k threads cat /proc/sys/kernel/threads-max

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...