You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@activemq.apache.org by David Jencks <da...@yahoo.com> on 2008/03/14 07:49:41 UTC

thread safety problem in ServerSessionPoolImpl.getServerSession()?

While fixing https://issues.apache.org/activemq/browse/AMQ-1618 I  
noticed that although there are some half-hearted attempts to look  
like there's thread safety in this method (use of  
CopyOnWriteArrayList) actually its completely unsafe.

For instance

         if (idleSessions.size() > 0) {
             ServerSessionImpl ss = idleSessions.remove 
(idleSessions.size() - 1);

executed by 2 threads can easily result in one getting an index out  
of bounds error or one trying to remove a server session from an  
empty list.

Before I look at fixing it could anyone confirm that in fact this  
method should be thread safe?

thanks
david jencks


Re: thread safety problem in ServerSessionPoolImpl.getServerSession()?

Posted by Rob Davies <ra...@gmail.com>.
On 14 Mar 2008, at 06:49, David Jencks wrote:

> While fixing https://issues.apache.org/activemq/browse/AMQ-1618 I  
> noticed that although there are some half-hearted attempts to look  
> like there's thread safety in this method (use of  
> CopyOnWriteArrayList) actually its completely unsafe.
>
> For instance
>
>        if (idleSessions.size() > 0) {
>            ServerSessionImpl ss =  
> idleSessions.remove(idleSessions.size() - 1);
>
> executed by 2 threads can easily result in one getting an index out  
> of bounds error or one trying to remove a server session from an  
> empty list.
>
> Before I look at fixing it could anyone confirm that in fact this  
> method should be thread safe?
>
> thanks
> david jencks
>
Hi David,

yes - this class should be thread safe - If I remember correctly this  
class was subject to alot of contention - often resulting in deadlocks  
- will attempt to fix - and let you verify ;)


cheers,

Rob

http://open.iona.com/ -Enterprise Open Integration
http://rajdavies.blogspot.com/