On Wed, Feb 18, 2009 at 11:04 PM, Emmanuel Lecharny <[email protected]>wrote:

>
>  Logically, one thread is associated with one session, that's the idea.
>>> If you have more than one thread writing data in one single session,
>>> then yes, you may have problems...
>>>
>>>
>>
>>
>>
>> Emmanuel, I don't understand what you are saying.
>>
>>
> What I mean is that once the server receive a message, it selects a thread
> to handle this message within its session. And if you have more than one
> thread writing in a session, it may not be thread safe.


I strongly disagree. IoSession is declared to be thread-safe. See the
javadoc [1]:

"IoSession<http://mina.apache.org/report/trunk/apidocs/org/apache/mina/common/IoSession.html>is
thread-safe. But please note that performing more than one
write(Object)<http://mina.apache.org/report/trunk/apidocs/org/apache/mina/common/IoSession.html#write%28java.lang.Object%29>calls
at the same time will cause the
IoFilter.filterWrite(IoFilter.NextFilter,IoSession,WriteRequest)<http://mina.apache.org/report/trunk/apidocs/org/apache/mina/common/IoFilter.html#filterWrite%28org.apache.mina.common.IoFilter.NextFilter,%20org.apache.mina.common.IoSession,%20org.apache.mina.common.WriteRequest%29>is
executed simultaneously, and therefore you have to make sure the
IoFilter<http://mina.apache.org/report/trunk/apidocs/org/apache/mina/common/IoFilter.html>implementations
you're using are thread-safe, too. "






>
>  I've never tried it because my apps don't need this, but I've always had
>> the
>> impression that multiple threads writing to the same IoSession
>> simultaneously should work.
>>
>>
> I think that the key is how you enforce this simultaneous writing. Now, if
> you consider that the server is reacting to incoming messages, then there is
> only one thread writing in a session, as this thread has been selected to
> deal with the incoming message.
>
> If your handler spawn more than one thread, which all write something, I
> have no idea how the server can behave. This is something I never thought
> could be done, or worth to be done. May be it's simply not supported...


It has always been supported. And I think we definitely should keep
supporting it.

What you are saying is "only call ioSession.write from within your
messageReceived handler, and only on the session that generated the event".
It's the first time I see claims like that.

This rule would make it (nearly) impossible to write a chat-server.
I checked our chat-server example [2] and according to your rules it's
broken.

The broadcast method syncronizes on the private member "sessions" but not on
the individual IoSession instances.

Besides, I haven't see doco saying on what we should syncrhonize when
writing simultanously to the same session from mulltiple threads.

I think this it's fundamental that all MINA committers agree on whether
IoSession should be thread-safe.
And when the answer is "no" we should fix the documentation.

Regards,
Maarten

[1]
http://mina.apache.org/report/trunk/apidocs/org/apache/mina/common/IoSession.html
[2]
http://mina.apache.org/report/trunk/xref/org/apache/mina/example/chat/ChatProtocolHandler.html#122


>
> At this point, some small test demonstrating the problem could help, I
> think.
>
>> And that in the past, it is has been advertised to work.
>>
>> But we do have an open bug about it:
>> https://issues.apache.org/jira/browse/DIRMINA-653
>>
>> wdyt ?
>>
>>
> Seems that it's an extreme scenario, not likely to be used in real life,
> but I may be wrong ?
>
> --
> --
> cordialement, regards,
> Emmanuel Lécharny
> www.iktek.com
> directory.apache.org
>
>
>

Reply via email to