Solved

Threads

Posted on 2002-04-27
3
187 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now