开发者

How many threads can be managed in Java 1.7?

How many threads is Java 1.7 are capable of managing?

In a Server/Client Web Program where clients can login to the server. This login i开发者_如何学Gos stateful.

Clients > 3000 per Server


"Enough". If not, you use thread pools with an appropriate Executor. What is it you need to do?


Java has APIs which limit the number of Threads to Integer.MAX_VALUE. (~ 2 billion)

However your OS/Hardware will be the real restriction. Between 100 and 10K will be your limit depending on what you are doing.

Threads are usually created to improve performance. However they add overhead so you will reach a point where adding threads will decrease performance. In rare cases two threads are not as good as one. The point at which more threads hurts performance depends on your application, your hardware and how it is used.

Note: If you have 16 logical cores, there will only be up to 16 threads running at any given moment.


There isn't a Java 1.7 (yet). On a 64-bit system you can go to tens of thousands. On 32-bit systems you are largely limited to virtual address spaces for stacks.

Long page on the "c10k" problem.


In theory? Thousands.

In practice - depends entirely on your system. You're more likely to run out of memory before you run out of threads.


I would imagine the upper bound has some relation to the available heap space. But the realistic limit has more to do with the hardware you are running the system on than the version of Java.


Each thread has its own stack space. The stack is stored outside of the heap but within the JVM's allocated memory. Thus the maximum threads is typically bound by how much memory the OS can allocated to the JVM. On Windows this corresponds to about 1000-2000 maximum threads before the JVM is out of memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜