Article View: borland.public.jbuilder.java.language
Article #7883Re: Server that listens to a port
From: Calvin R. Smith
Date: Thu, 10 May 2001 19:56
Date: Thu, 10 May 2001 19:56
106 lines
4371 bytes
4371 bytes
Performance:
A program with a lot of threads can actually hurt performance since the
computer will spend most of it's time switching between the threads so it's
a good idea to limit the number of threads a program uses. Most server
programs (including apache) have a way to specify maximum connections. This
number will probably be high on a fast machine and low on a slow machine.
I understand that you would like to have 'unlimited connections' but
doing so will cause your machine to thrash so play with the limit for your
machine.
Thread Pool:
A thread pool is simply a pool of threads that are not in use. for
example if you had 20 connections at once then 5 of them finished you could
place the 5 finished threads in a pool for next time a connection is wanted.
This helps since creation of a thread takes a while.
Skeleton code for waiting for a connection
while (the program is waiting for connections)
{
threadPool.get().handleConnection(ServerSocket.accept();
}
Skeleton code for dealing with a socket
...
public void handleConnection(Socket sock)
{
talk to the socket till done
add the socket back to the pool
threadpool.put(this);
}
thread pool is a simple pool patern.
"ArShAm" <ArShAm_MeTaL@hotmail.com> wrote in message
news:3afaec55_2@dnews...
> what did you mean : "for performance limit the maximum number of
connections
> and use a thread pool for waiting connections"
> I didn't get about the pool.
> And assume we can't determine the number of connections , maybe
unlimitted.
> What can I do for that?
>
> Excuse me ,Would you please show me the skletton of that two kind of
threads
> you told? Thanks
>
>
> ArShAm
>
>
>
>
> "Calvin R. Smith" <calvinrsmith@hotmail.com> wrote in message
> news:3afadec3$1_2@dnews...
> > for sockets that are used by muli-clients what you should on the server
> is:
> > - create a thread that waits for a connection
> > - when a connection is made pass the connection to another thread
> > - go back to waiting for a connection
> > - the thread that got handed a connection should only deal with that
> > connection - it knows nothing about the other connections.
> >
> > for performance limit the maximum number of connections and use a thread
> > pool
> > for waiting connections
> >
> > "ArShAm" <ArShAm_MeTaL@hotmail.com> wrote in message
> > news:3afac731_2@dnews...
> > > Hi there
> > >
> > > How to listen to a port , while 3 clients wait for accept that ? and
how
> > to
> > > handle the inputs?
> > > Is there any events that can handle the ports for inputing?
> > > Which method for threading is better?
> > > 1.Each objects(each clients has an object to read from and write
to)
> > has
> > > a thread for itself , and in run() method , it invoke yeld()
> > > 2.The main class controls the threads
> > >
> > >
> > > Can I do this?( if I can , this is the best Idea I think ) :
> > > each clients when send a msg to a port , it contains a code for client
,
> > and
> > > the server then knows the data is belongs to which client , and invoke
> the
> > > methods of the client class.If I can do this , how to listen to a port
,
> > and
> > > the other way , how to accept the port? I want to get a password from
> > > clients , and then if password was incorrect , close the connection of
> the
> > > client.
> > >
> > > Thanks
> > > ArShAm
> > >
> > >
> >
> >
>
>
Technical Details
Message-ID:
<3afaf2d9$1_2@dnews>Path:
arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!sn-uk-xit-01!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3afac731_2@dnews> <3afadec3$1_2@dnews> <3afaec55_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,43e608b758a1dc81 X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-05-10 13:28:06 PST From: "Calvin R. Smith" <calvinrsmith@hotmail.com> Newsgroups: borland.public.jbuilder.java.language References: <3afac731_2@dnews> <3afadec3$1_2@dnews> <3afaec55_2@dnews> Subject: Re: Server that listens to a port Date: Thu, 10 May 2001 13:56:33 -0600 Lines: 108 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 207.201.104.90 Message-ID: <3afaf2d9$1_2@dnews> X-Trace: dnews 989524697 207.201.104.90 (10 May 2001 12:58:17 -0700) Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!sn-uk-xit-01!supernews.com!diablo.theplanet.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews