> It is also guaranteed by the framework that only one I/O dispatch
> thread can interact with the same I/O session at a time.

That is what I wanted to know. Thank you very much Oleg.


On Thu, Mar 27, 2014 at 2:49 PM, Oleg Kalnichevski <[email protected]> wrote:

> On Thu, 2014-03-27 at 14:13 +0530, Sajith Dilshan wrote:
> > Hi Oleg,
> >
> > Thank you for the reply. But I'm still a bit confused about the answer.
> So
> > let me rephrase my question. When a worker thread enters
> > outputReady(IOSession session) method with that session object, does that
> > worker thread acquires a lock on  OP_WRITE operation for that particular
> > session object so that any other worker thread can't perform OP_WRITE
> > operation on that session object?
> >
>
> Only I/O event dispatch threads managed by the I/O reactor should ever
> call IOEventDispatch#outputReady. It is also guaranteed by the framework
> that only one I/O dispatch thread can interact with the same I/O session
> at a time.
>
> If your application create additional worker threads those threads
> should never call IOEventDispatch#outputReady. They should only interact
> with IOSession, update its state but let the I/O dispatch threads do the
> actual reading and writing.
>
> > As an example, assume there are two worker threads, Thread_A and
> Thread_B.
> > Further, there is a IOSession object session_123 with its event set as
> > OP_WRITE. Both threads, Thread_A and Thread_B see that OP_WRITE event is
> > set for session_123 and can the both threads (Thread_A, Thread_B) enter
> the
> > outputReady(IOSession session) method at the same time with the
> session_123
> > being the parameter passed to that method and execute the method's body?
> >
>
> See above. Worker threads should update IOSession's state (such as
> shared I/O buffer) but the actual writing should be performed by the I/O
> dispatch thread.
>
> There is a section on asynchronous I/O control for HTTP connections you
> may find useful:
>
>
> http://hc.apache.org/httpcomponents-core-4.3.x/tutorial/html/nio.html#d5e614
>
> Oleg
>
> >
> > On Thu, Mar 27, 2014 at 1:52 PM, Oleg Kalnichevski <[email protected]>
> wrote:
> >
> > > On Wed, 2014-03-26 at 23:00 +0530, Sajith Dilshan wrote:
> > > > Hi everyone,
> > > >
> > > > When I set the OP_WRITE event on a particular instance of
> > > > org.apache.http.nio.reactor.IOSession, a worker thread will pick up
> that
> > > > IOSession and will execute the outputReady(IOSession session) method
> of
> > > the
> > > > respective org.apache.http.nio.reactor.IOEventDispatch
> implementation.
> > > >
> > > > My question is that, is it possible for more than one thread to
> execute
> > > > outputReady(IOSession session) method for the same instance of
> IOSession
> > > at
> > > > the same time?
> > >
> > > it is possible on multi CPU core systems.
> > >
> > > > Does a worker thread acquires a lock before executing
> > > > outputReady(IOSession session) method for a particular IOSession
> > > instance?
> > > >
> > >
> > > Yes, it does. Access to IOSession's internal structures is
> synchronized.
> > > IOSession-s are fully thread safe.
> > >
> > > Oleg
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [email protected]
> > > For additional commands, e-mail: [email protected]
> > >
> > >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to