On 9/4/11 10:38 AM, Antonio Rodriges wrote:
Hello,
I am experimenting with Apache Mina and currently have unclear point:
In NioSocketAcceptor acceptor = new NioSocketAcceptor(2);
I specify the number of acceptors. As fa as I understand they do not
work in separate threads.
They do.
When I try to perform long operation in
IoHandlerApadter.messageReceived and new connection is established, a
free NioAcceptor is working, e.g. code with 2 NioAcceptors work:
public class MyIOHandler extends IoHandlerAdapter {
...........
private static long number = 0;
public void messageReceived(IoSession session, Object message) throws
Exception {
number++;
if (number == 1) {
while(true) { }
}
}
...........
}
the first NioAcceptor buisy, when new connection required, the second
remaining acceptor takes over
Plain normal.
I wonder why it works if I have only 1 thread (with no
ExecutorFilter)?
Just because each acceptor runs on its own thread :)
What is the philosophy behind Mina acceptors?
One acceptor = one thread. I don't think it's useful to create an
acceptor with a specific value, the default constructor will pick a
number of thread to create depending on your machine's configuration
(the rule is to create as many thread as you have CPU's, plus one)
Is code
inside IoHandlerAdapter thread safe or I must perform synchronization?
There is one guarantee : once a session is associated with one
IoProcessor instance, it will be attached to the associatd thread. So if
you don't add an executor in your chain, then it's supposed to be
thread-safe. However, if you have cross-sessions elements, it's up to
you to protect them against concurrent access.
If you add an executor, then it's a different story.
Hope it helps...
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com