views:

120

answers:

6

How many threads about Java 1.7 are capable of managing? In Server/Client Web Program wich clients can login To Server. This Login is statefull. Clients > 3000 per Server

A: 

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.

Matt
Not heap space. On 32-bit systems, virtual address space for stacks.
Tom Hawtin - tackline
+1  A: 

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.

Tom Hawtin - tackline
Thanks for your link.
DanialAbdi
+1  A: 

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.

Visage
+3  A: 

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

Thorbjørn Ravn Andersen
Connection Management
DanialAbdi
Have a look at JBoss Netty. http://jboss.org/netty
Thorbjørn Ravn Andersen
A: 

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.

Steve Kuo
Java threads use OS allocated stack space, which is __NOT__ assigned to the JVM. There is a small amount of JVM memory associated with each thread stack, but the actual stack is allocated out of OS process memory __external__ to the JVM, making the JVM use less memory Xmx/Xms can actually __increase__ the number of available threads
fuzzy lollipop
+1  A: 

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.

Peter Lawrey