Solved

Threads

Posted on 2002-04-27
3
192 Views
Last Modified: 2010-03-31
Hi All

I am writing application which suppose to accept unlimited number of users via sockets.
I am dealing with the following question: Should I create thread in the system for each socket to handle each client or should I create number of thread to handle all sockets?
I am working under Windows NT system.
What are the advantages and disadvantages for each way?
Is there any restrictions for number of thread for each process under NT?
If you have any link for researched done in this area, it will be helpful.
   
     Thanks.
0
Comment
Question by:dannysh
3 Comments
 

Expert Comment

by:sunilvirus
ID: 6975213
It all depends on your application.
If your application requires lot of interaction with the clients(through sockets) then it is advisable to have one thread for each client.
Typical example is chatting with private windows.

There is a limit on the number of threads that can be created. I dont know the exact number on NT system.
0
 

Author Comment

by:dannysh
ID: 6976396
Is there realy limitation about the number of thread I can create?
0
 
LVL 5

Accepted Solution

by:
nebeker earned 50 total points
ID: 6978045
In the JDK 1.4, you can now use "select" to monitor a large number of active sockets with a small number of active threads.  Take a look at:

java.nio.channels.Selector

My suggestion would be to create a small thread pool.  The threads in the pool will take turns calling select() to find a socket with data, and then process that data...  When the thread is finished, it is returned to the pool, where it again waits in line to call select() and perform more work.

The thread pool could be fixed in size, or it could grow/shrink dynamically, based on the amount of work available.

Yes, there are limitations to the number of threads that you can create -- as well as memory overhead associated with each thread.   The absolute limit is dependent on the platform, but I think you'll run into memory problems first....

No matter what platform you're using, I doubt you'll get enough threads running to support an "unlimited number of users". :)

If you really suspect that you'll have that many users (i.e. thousands or tens of thousands), then you probably need to look at some kind of load-balancing solution.  
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Oracle SQL syntax check  without executing 6 75
SHA2 certs for IIS AND Java? 2 113
How to convert from xls to xlsx using java 7 55
Selenium docs api java index 3 48
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question