Solved

Threads

Posted on 2002-04-27
3
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

751 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