mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emmanuel Lécharny <elecha...@gmail.com>
Subject Re: Multithreading Client/Server Application
Date Wed, 06 Mar 2013 17:48:07 GMT
Le 3/6/13 6:16 PM, IronMan a écrit :
> Hi,
> I want to develop a multithreading Client/Server Application using Apache
> MINA.
> I have find many examples for the single-thread case, but nothing for
> multithread. There is documentation for the multithread case?

MINA allows you to design a multi-threaded server natively. In fact, it
*is* multi-threaded.

There is nothing special you have to do to deal with multi-threaded
aspects, except to be sure that you have a thread-safe application.

Let me explain how it works :

1) A client connects to the server : a thread is picked to process the
request. This thread will always be used for every request sent by this
client (unless you start playing with an executor in the middle of your
code)
2) Once the server has received the request, and ha sprocessed it, it
can send back a rrsponse : this is done on the same thread
3) And that's it.

If you have a second client, it will use another thread.

Ok, now, at some point, it's not anymore a One client/One thread
association. We have a limited number of threads available (default to
Nb processor +1), so when we reach the max number of thread, we reuse
the first thread (this is a round robin mechanism).

So many clients can use the same thread. Still, this is safe as one
client won't be able to user the thread that is already used by another
client : it will be queued waiting for the previous client to be done.

That's the way it works. Its an overly simplified explaination though.
You just have to give it a try, you'll see it works pretty well.

-- 
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com 


Mime
View raw message