File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Limitations Of Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Limitations Of Threads" Watch "Limitations Of Threads" New topic
Author

Limitations Of Threads

merwin pinto
Ranch Hand

Joined: Feb 16, 2005
Posts: 39
Hi,
I was writing a program for a Chat Server .... now by using threads, the server can possibly handle about 700 to 800 clients. Each client has a thread running on its behalf. this is b coz a single runtime can handle just as many threads .
Now my question is : Is there a principle or a method by which i have the server handle more number of clients connecting ? may be a few thousand clients...
thanks a lot
regards
Merwin
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
There is a limit to the number of threads a single JVM can handle.
This is imposed by the hardware mainly (at some point the JVM will be so busy managing all those threads that it doesn't get to run any of them).
There's nothing you can do about that, you'll have to start thinking about distributed computing.
Have multiple servers talking to each other, each handling part of the load.
For each server all the others are a special kind of user...


42
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I'd go back and look at your design. Do you need a thread per user? Or a thread per incoming message? Here's typical server logic:

Now you need only as many threads as you have SIMULTANEOUS requests. But if traffic is high you're still setting up and tearing down a lot of threads, which can hurt performance. That leads us to look at thread pools. JDK 5.0 has great pooling stuff under the Executor interface. Then the logic looks like:

If there is an available thread, the thread will pull the request out of the queue and process it immediately. Otherwise the request will wait in queue until a thread finishes what it's doing and gets another from the queue.

Does that sound promising?

[ EJFH: Fixed mismatched CODE tags. ]
[ February 18, 2005: Message edited by: Ernest Friedman-Hill ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Limitations Of Threads
 
Similar Threads
client and lock
how many instances can a runtime handle
How many instance of a class can a single runtime can handle
Need Help::Any Ideas for a Networking Project involving Socket Programming
ATM code not working