Synchronized is important to update the thread caches. More so when
different sessions are bound to different threads.
On Nov 21, 2013 10:45 AM, "Alexandros Touloupis" <atoulou...@gmail.com>
wrote:

> Thanks for the reply!
>
> Yes I agree that synchronizing to the whole IoSession instance each time
> for writing, is brutal. I am thinking on including a writing lock as a
> session attribute in each session that will be initialized on
> sessionCreated events.
>
> Cheers!
> Alex
>
>
> On Thu, Nov 21, 2013 at 4:28 PM, Jon V. <sybersn...@gmail.com> wrote:
>
> > I would imagine this to be true. The normal use case is request and
> > response. Additional synchronization makes the code run slower in that
> > scenario. I would suggest synchronizing critical paths.
> >
> > I have to synchronize write paths for the same reason where one input may
> > write to dozens of other sockets.
> > On Nov 21, 2013 10:23 AM, "Alexandros Touloupis" <atoulou...@gmail.com>
> > wrote:
> >
> > > Hello all,
> > >
> > > I am using mina 2.0.8 since I needed a patch included in this release.
> > >
> > > I face the following problem:
> > >
> > > The concept of the application is to "multiplex" inbound to outbound
> > > connections in MINA. This means that there might be 2 incoming
> > connections
> > > that are multiplexed in one outbound connection. During my tests i
> > randomly
> > > see this exception:
> > >
> > > java.nio.InvalidMarkException
> > >         at java.nio.Buffer.reset(Buffer.java:298) ~[?:1.7.0_40]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.buffer.AbstractIoBuffer.reset(AbstractIoBuffer.java:414)
> > > ~[mina-core-2.0.8-PATCHED.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.polling.AbstractPollingIoProcessor.writeBuffer(AbstractPollingIoProcessor.java:926)
> > > ~[mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.polling.AbstractPollingIoProcessor.flushNow(AbstractPollingIoProcessor.java:844)
> > > [mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.polling.AbstractPollingIoProcessor.flush(AbstractPollingIoProcessor.java:772)
> > > [mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.polling.AbstractPollingIoProcessor.access$700(AbstractPollingIoProcessor.java:67)
> > > [mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.core.polling.AbstractPollingIoProcessor$Processor.run(AbstractPollingIoProcessor.java:1112)
> > > [mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:64)
> > > [mina-core-2.0.8-SNAPSHOT.jar:?]
> > >         at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> > > [?:1.7.0_40]
> > >         at
> > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> > > [?:1.7.0_40]
> > >         at java.lang.Thread.run(Thread.java:724) [?:1.7.0_40]
> > >
> > > After some investigation i noticed that this happened when 2 threads
> > > decided to write to the same IoSession a message the same time. My
> > > assumption is that the #IoSession.write method is not thread safe,
> thus i
> > > synchronized the session instance before executing the write method in
> my
> > > handlers and up until now i haven't faced the same issue. Is my
> > assumption
> > > valid?
> > >
> > > Thank you in advance,
> > > Alex
> > >
> >
>

Reply via email to