Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Threads

Posted on 2002-04-27
3
Medium Priority
?
196 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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

722 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