User: hiram   
  Date: 01/02/13 16:41:33

  Modified:    src/main/org/jbossmq SpyConnection.java
  Log:
  Bug Fix: Client programs were exiting even when they had registed an async receiver.
  Client program now will not exit until a connection.close() is performed.
  Reported by Peter
  
  Revision  Changes    Path
  1.2       +31 -1     jbossmq/src/main/org/jbossmq/SpyConnection.java
  
  Index: SpyConnection.java
  ===================================================================
  RCS file: /products/cvs/ejboss/jbossmq/src/main/org/jbossmq/SpyConnection.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SpyConnection.java        2001/01/26 00:43:30     1.1
  +++ SpyConnection.java        2001/02/14 00:41:33     1.2
  @@ -38,7 +38,7 @@
    *   @author Norbert Lataille ([EMAIL PROTECTED])
    *   @author Hiram Chirino ([EMAIL PROTECTED])
    * 
  - *   @version $Revision: 1.1 $
  + *   @version $Revision: 1.2 $
    */
   public class SpyConnection implements java.io.Serializable, javax.jms.Connection {
        //////////////////////////////////////////////////////////////
  @@ -89,6 +89,20 @@
                clientID = cID;
                crClassName = crCN;
                spyXAResourceManager = new SpyXAResourceManager(this);
  +
  +             // Stop Asynch based programs from exiting out due to no
  +             // non-deamon threads running.  We start one here that lives
  +             // untill the connection is closed().
  +             connectionThread = new Thread("SpyConnection Thread") {
  +                     synchronized public void run() {
  +                             try {
  +                                     this.wait(); // Wait for close() to stop me
  +                             } catch ( InterruptedException e ) {
  +                             }
  +                     }
  +             };
  +             connectionThread.start();
  +             
        }
   
        //////////////////////////////////////////////////////////////
  @@ -214,6 +228,13 @@
                }
                Log.log("Disconnected from server");
   
  +
  +             // Stop the non deamon thread that we created.
  +             synchronized (connectionThread) {
  +                     connectionThread.notify();
  +                     connectionThread.interrupt();
  +             }
  +             
                // Only set the closed flag after all the objects that depend 
                // on this connection have been closed.
                closed = true;
  @@ -297,6 +318,8 @@
                        synchronized (exceptionListener) {
                                exceptionListener.onException(excep);
                        }
  +             } else {
  +                     Log.error(e);
                }
   
                throw excep;
  @@ -545,4 +568,11 @@
                        failureHandler(e, "Cannot acknowlege a message.");
                }
        }
  +
  +     // The connectionThread is a non-deamon thread that
  +     // runs until the connection is closed().  This allows
  +     // Writing asynch client programs that do not create
  +     // long running threads.  The program would terminate when
  +     // the connection is closed()
  +     Thread connectionThread;
   }
  
  
  

Reply via email to