How many active Threads is possible?

C

Chris Berg

This is an actual-VM question, not a language question:

How many active threads can I create?

Of course, it is dependent on the platform and the VM implementation,
so I'll narrow the question to two examples:

1) 2 GHZ P4, 512 MByte RAM, running Sun JRE on Windows 2000. No other
significant programs running.
2) Same, but Linux.

My actual app is a server that has to accept many Socket connections.
I could set up a test bench, but if anyone has some experience, I'd be
peased to get some idea of the figures. Are we talking 10's? 100's,
10000's?

Chris
 
M

Michael Borgwardt

Chris said:
This is an actual-VM question, not a language question:

How many active threads can I create?

Of course, it is dependent on the platform and the VM implementation,
so I'll narrow the question to two examples:

1) 2 GHZ P4, 512 MByte RAM, running Sun JRE on Windows 2000. No other
significant programs running.
2) Same, but Linux.

My actual app is a server that has to accept many Socket connections.
I could set up a test bench, but if anyone has some experience, I'd be
peased to get some idea of the figures. Are we talking 10's? 100's,
10000's?

Chris
 
M

Michael Borgwardt

Oops, pressed "send" by accident...

Chris said:
My actual app is a server that has to accept many Socket connections.
I could set up a test bench, but if anyone has some experience, I'd be
peased to get some idea of the figures. Are we talking 10's? 100's,
10000's?

I think you'll face a resource problem before actually running out of
threads, since each thread gets IIRC 256KB stack by default.
Of course this can be set to a lower value, but it's probably a better
idea to use a java.nio.channels.SelectableChannel which allows you to
handle many connection with one thread.
 
C

Chris Berg

nio seems to be a good alternative, thanks for the advice.

Looking at nio, however, it seems that I have to re-write parts of my
application, as the whole idea is to get rid of the threads. That
means, that the handling of data on the separate client sockets must
happen non-blocking, which is not always possible. For instance, if a
client wants the server to read a disk file and send data from that
file, then the file-read operation, which may block the running
thread, will also block response to all other sockets, resulting in
poor response times and not using the CPU time 100%.

Could the way out of that mess be to replace all disk-access with nio
as well?

Chris
 
M

Michael Borgwardt

Chris said:
nio seems to be a good alternative, thanks for the advice.

Looking at nio, however, it seems that I have to re-write parts of my
application, as the whole idea is to get rid of the threads. That
means, that the handling of data on the separate client sockets must
happen non-blocking, which is not always possible. For instance, if a
client wants the server to read a disk file and send data from that
file, then the file-read operation, which may block the running
thread, will also block response to all other sockets, resulting in
poor response times and not using the CPU time 100%.

Could the way out of that mess be to replace all disk-access with nio
as well?

I'm not sure. I don't have much experience with java.nio myself, but I
remember hearing somewhere that it's only non-blocking for sockets,
not for files, but I may misremember that.

An alternative may be to have a limited-size pool of threads that processes
requests in parallel so that if some are blocked on IO, the others can
still continue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top