You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Michael Bauroth <mi...@falcom.de> on 2007/07/11 08:43:11 UTC
Synchronization in IoSessionHandler
Hi,
just a short question: The IoSessionHandler will be called in most cases
from concurrent threads in the same time. Right? I ask, because I have
to implement in this case some sort of synchronization in each of the
methods (messageReceived ...)
Best Regards
Michael
Re: Synchronization in IoSessionHandler
Posted by Michael Bauroth <mi...@falcom.de>.
Thanx to both! I will try it.
Michael
Maarten Bosteels schrieb:
> On 7/11/07, Trustin Lee <tr...@gmail.com> wrote:
>>
>> On 7/11/07, Michael Bauroth <mi...@falcom.de> wrote:
>> > Hi,
>> >
>> > just a short question: The IoSessionHandler will be called in most
>> cases
>> > from concurrent threads in the same time. Right? I ask, because I have
>> > to implement in this case some sort of synchronization in each of the
>> > methods (messageReceived ...)
>>
>> If the number of connection is greater than 1, yes. If you are
>> accessing a shared resource in your handler implementation, you need
>> synchronization, which might degrade performance if the shared
>> resource is expensive to access.
>
>
>
> Michael, you could/should try to find the most appropriate synchronization
> mechanism for your use-case.
> For instance, when most access to the shared resource is read-only, you
> could increase performance by using a ReadWriteLock instead of 'ordinary'
> synchronization.
>
> http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html
>
>
> Maarten
>
> HTH,
>> Trustin
>> --
>> what we call human nature is actually human habit
>> --
>> http://gleamynode.net/
>> --
>> PGP Key ID: 0x0255ECA6
>>
>
Re: Synchronization in IoSessionHandler
Posted by Maarten Bosteels <mb...@gmail.com>.
On 7/11/07, Trustin Lee <tr...@gmail.com> wrote:
>
> On 7/11/07, Michael Bauroth <mi...@falcom.de> wrote:
> > Hi,
> >
> > just a short question: The IoSessionHandler will be called in most cases
> > from concurrent threads in the same time. Right? I ask, because I have
> > to implement in this case some sort of synchronization in each of the
> > methods (messageReceived ...)
>
> If the number of connection is greater than 1, yes. If you are
> accessing a shared resource in your handler implementation, you need
> synchronization, which might degrade performance if the shared
> resource is expensive to access.
Michael, you could/should try to find the most appropriate synchronization
mechanism for your use-case.
For instance, when most access to the shared resource is read-only, you
could increase performance by using a ReadWriteLock instead of 'ordinary'
synchronization.
http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/locks/ReadWriteLock.html
Maarten
HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>
Re: Synchronization in IoSessionHandler
Posted by Trustin Lee <tr...@gmail.com>.
On 7/11/07, Michael Bauroth <mi...@falcom.de> wrote:
> Hi,
>
> just a short question: The IoSessionHandler will be called in most cases
> from concurrent threads in the same time. Right? I ask, because I have
> to implement in this case some sort of synchronization in each of the
> methods (messageReceived ...)
If the number of connection is greater than 1, yes. If you are
accessing a shared resource in your handler implementation, you need
synchronization, which might degrade performance if the shared
resource is expensive to access.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6