Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Threads

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
dannysh
Asked:
dannysh
1 Solution
 
sunilvirusCommented:
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
 
dannyshAuthor Commented:
Is there realy limitation about the number of thread I can create?
0
 
nebekerCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now