You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Geoff Cadien <gc...@gmail.com> on 2008/02/14 18:41:48 UTC

Question About WriteFuture and Multiple Threads

I'm experiencing different behavior when calling IoSession.write() and then
adding an IoFutureListener to the returned WriteFuture depending on the
thread from which the IoSession.write is called.  Example:

WriteFuture future = session.write(someMessage);
future.addListener(someListener);

Now if that snippet of code is executed from the IoProcessor thread I see
the IoFutureListener.operationComplete called followed by
IoHandler.messageSent called.

If the above snippet is called from a different there seems to be a race.
Sometimes IoFutureListener.operationComplete is called followed by
IoHandler.messageSent and sometimes the other way around.  What seems to be
happening is that when IoSession.write is called (from a non IoProcessor
thread) IoFilterChain.filterWrite is fired, the message is added to the
IoSession writeRequestQueue, and the IoProcessor writes the message and
fires messageSent before the IoFutureListener is added to the WriteFuture.

So my question is is this the expected behavior or is it a bug?

-geoff

Re: Question About WriteFuture and Multiple Threads

Posted by Geoff Cadien <gc...@gmail.com>.
On Feb 19, 2008 7:56 PM, 이희승 (Trustin Lee) <tr...@gmail.com> wrote:

> Hi Geoff,
>
> There's no direct relationship in the order of events between
> IoFutureListener and IoHandler, that is, they are designed to be
> independent from each other in event order.


Thanks Trustin.  I assumed that  was probably the case but just wanted to
make sure.

Thanks,

-geoff

Re: Question About WriteFuture and Multiple Threads

Posted by "이희승 (Trustin Lee)" <tr...@gmail.com>.
Hi Geoff,

There's no direct relationship in the order of events between
IoFutureListener and IoHandler, that is, they are designed to be
independent from each other in event order.

HTH,

2008-02-14 (목), 10:41 -0700, Geoff Cadien 쓰시길:
> I'm experiencing different behavior when calling IoSession.write() and then
> adding an IoFutureListener to the returned WriteFuture depending on the
> thread from which the IoSession.write is called.  Example:
> 
> WriteFuture future = session.write(someMessage);
> future.addListener(someListener);
> 
> Now if that snippet of code is executed from the IoProcessor thread I see
> the IoFutureListener.operationComplete called followed by
> IoHandler.messageSent called.
> 
> If the above snippet is called from a different there seems to be a race.
> Sometimes IoFutureListener.operationComplete is called followed by
> IoHandler.messageSent and sometimes the other way around.  What seems to be
> happening is that when IoSession.write is called (from a non IoProcessor
> thread) IoFilterChain.filterWrite is fired, the message is added to the
> IoSession writeRequestQueue, and the IoProcessor writes the message and
> fires messageSent before the IoFutureListener is added to the WriteFuture.
> 
> So my question is is this the expected behavior or is it a bug?
> 
> -geoff
-- 
Trustin Lee - Principal Software Engineer, JBoss, Red Hat
--
what we call human nature is actually human habit
--
http://gleamynode.net/