You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Andy Myint <an...@gmail.com> on 2009/06/10 09:08:48 UTC

How to make IoAcceptor Multi thread

Do I need to make my IoHandler thread-safe?

It depends on your implementation. If you access the resource which is
shared across multiple sessions, you have to make it thread-safe. If the
resource is not shared at all and accessed by only one session (e.g. storing
context information as a session attribute), then you don't need to make it
thread-safe. It is because all events generated by MINA are transmitted to
your handler in order (when using the Executor Filter), and the newer event
is not processed if the event handler method for the older event for the
same session hasn't returned yet.


IoAcceptor is processing message in order. How can I make IoAcceptor send
event to iohandler asynchronously so that iohandler will be receving events
without having to wait for previous one to be finished. Following is my
spring config.


    <bean id="ioAcceptorUDP"
class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor"
init-method="bind" destroy-method="unbind">
        <property name="defaultLocalAddress" value="${listener.port.udp}" />
        <property name="handler" ref="udpHandler" />
        <property name="filterChainBuilder" ref="filterChainBuilder" />
    </bean>

Re: How to make IoAcceptor Multi thread

Posted by Emmanuel Lecharny <el...@apache.org>.
I guess that there is a mix of question and answer in this mail. Let's 
try to add some info ...

Andy Myint wrote:
> Do I need to make my IoHandler thread-safe?
>
> It depends on your implementation. If you access the resource which is
> shared across multiple sessions, you have to make it thread-safe. If the
> resource is not shared at all and accessed by only one session (e.g. storing
> context information as a session attribute), then you don't need to make it
> thread-safe. It is because all events generated by MINA are transmitted to
> your handler in order (when using the Executor Filter), and the newer event
> is not processed if the event handler method for the older event for the
> same session hasn't returned yet.
>   
I would add that you must use MINA-2.0.0-M6, the previous versions have 
bugs in this area.
>
> IoAcceptor is processing message in order.
Not exactly the acceptor. NioProcessor are processing incoming and 
outgoing message for an established connection (session).
>  How can I make IoAcceptor send
> event to iohandler asynchronously so that iohandler will be receving events
> without having to wait for previous one to be finished. Following is my
> spring config.
>   
You can use an executorFilter with a UnorderedThreadPoolExecutor.

Keep in mind that the IoHandler don't wait for events. IoHandler are 
called when some events are present.
>
>     <bean id="ioAcceptorUDP"
> class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor"
> init-method="bind" destroy-method="unbind">
>         <property name="defaultLocalAddress" value="${listener.port.udp}" />
>         <property name="handler" ref="udpHandler" />
>         <property name="filterChainBuilder" ref="filterChainBuilder" />
>     </bean>
>
>   


-- 
--
cordialement, regards,
Emmanuel Lécharny
www.iktek.com
directory.apache.org