PATCH : jmsServerSessionPool

"Day, Jem BGI WAC" <[email protected]>
Newsgroups gmane.comp.java.openjms.devel
Message-ID <A85895DA0338D411B9E900508B950CC90267CB30@calntexc012.insidelive.net>
Hi,

  There seemed to be a potential synchronization problem when
  an attempt was made to obtain a session from the Pool.

  I changed getServerSession() to :


  Attached is a diff file.

  public ServerSession getServerSession()
        throws JMSException
    {
        ServerSession result = null;

        try
        {
            synchronized(sessionPool_)
            {

                while (sessionPool_.size() == 0)
                {
                    try {
                        // Wait for a Session to be returned.
                        sessionPool_.wait();
                    }
                    catch (InterruptedException ie)
                    {
                        // Swallow this
                    }
                }

                // Grab a Session.
                result = (ServerSession)sessionPool_.remove(0);
            }

        }
        catch (Exception exception)
        {
            throw new JMSException("Error in getServerSession " +
exception);
        }

        return result;
    }

Jem..

 

  
 <<diff.txt>>
diff.txt (text/plain, 3.3 KB)
cvs -z9 diff JmsServerSessionPool.java (in directory C:\open-source\openjms\src\main\org\exolab\jms\client)
Index: JmsServerSessionPool.java
===================================================================
RCS file: /cvsroot/openjms/openjms/src/main/org/exolab/jms/client/JmsServerSessionPool.java,v
retrieving revision 1.3
diff -r1.3 JmsServerSessionPool.java
47c47
<  * 
---
>  *
62,63c62,63
<  * This class is an example implements of the ServerSessionPool interface, 
<  * which is primarily by the application server facility. It is the 
---
>  * This class is an example implements of the ServerSessionPool interface,
>  * which is primarily by the application server facility. It is the
66c66
<  * The ServerSessionPool manages a collection of ServerSession objects, 
---
>  * The ServerSessionPool manages a collection of ServerSession objects,
75c75
<     implements ServerSessionPool 
---
>     implements ServerSessionPool
90c90
<      * @param       listener        message listener that sessions will be 
---
>      * @param       listener        message listener that sessions will be
94c94
<         
---
> 
100c100
<                // only assing it if it is greater than zero 
---
>                // only assing it if it is greater than zero
112c112
<                         new JmsServerSession(serverSessionPool__, listener));   
---
>                         new JmsServerSession(serverSessionPool__, listener));
130c130
<      * If init hasn't been called before retrieving the instance then a 
---
>      * If init hasn't been called before retrieving the instance then a
148c148
<     public ServerSession getServerSession() 
---
>     public ServerSession getServerSession()
155,156c155
<             // put an upper limit on the amount of time it waits
<             for (;;)
---
>             synchronized(sessionPool_)
158,163c157,158
<                 if (sessionPool_.size() > 0) 
<                 {
<                     result = (ServerSession)sessionPool_.remove(0);
<                     break;
<                 }
<                 else
---
> 
>                 while (sessionPool_.size() == 0)
165,170c160,162
<                     try
<                     {
<                         synchronized (sessionPool_)
<                         {
<                             sessionPool_.wait();
<                         }
---
>                     try {
>                         // Wait for a Session to be returned.
>                         sessionPool_.wait();
172c164
<                     catch (InterruptedException exception)
---
>                     catch (InterruptedException ie)
174c166
<                         // ignore the error
---
>                         // Swallow this
176a169,171
> 
>                 // Grab a Session.
>                 result = (ServerSession)sessionPool_.remove(0);
177a173
> 
181c177
<             throw new JMSException("Error in getServerSession " + exception); 
---
>             throw new JMSException("Error in getServerSession " + exception);
189c185
<      * Recycle the specified server session by appending it to the end of 
---
>      * Recycle the specified server session by appending it to the end of
212,213c208,209
<     
<     
---
> 
> 
240c236
<     private static boolean init__ = false; 
---
>     private static boolean init__ = false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.