avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/connection Connection.java
Date Fri, 12 Jul 2002 01:27:45 GMT
donaldp     2002/07/11 18:27:45

  Modified:    src/java/org/apache/avalon/cornerstone/blocks/connection
                        Connection.java
  Log:
  Add a guard so that connection that does not get a chance to
  start before dispose() is shutdown rather than causing hang.
  
  Revision  Changes    Path
  1.17      +19 -2     jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/connection/Connection.java
  
  Index: Connection.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/src/java/org/apache/avalon/cornerstone/blocks/connection/Connection.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- Connection.java	12 Jul 2002 01:25:12 -0000	1.16
  +++ Connection.java	12 Jul 2002 01:27:45 -0000	1.17
  @@ -127,6 +127,8 @@
       private Thread m_thread;
       private List m_runners;
       private ConnectionHandlerFactory m_handlerFactory;
  +    private boolean m_finished;
  +
   
       ConnectionRunner( final Socket socket,
                         final List runners,
  @@ -142,6 +144,7 @@
       {
           synchronized( this )
           {
  +            m_finished = true;
               if( null != m_thread )
               {
                   m_thread.interrupt();
  @@ -157,12 +160,24 @@
   
       public void run()
       {
  -        ConnectionHandler handler = null;
  -        try
  +        //Synchronized section to guard against
  +        //dispose() being called before thread is
  +        //run and reaches next section
  +        synchronized( this )
           {
  +            if( m_finished )
  +            {
  +                shutdownSocket();
  +                return;
  +            }
               m_thread = Thread.currentThread();
               m_runners.add( this );
  +        }
  +
   
  +        ConnectionHandler handler = null;
  +        try
  +        {
               debugBanner( true );
   
               handler = m_handlerFactory.createConnectionHandler();
  @@ -183,6 +198,8 @@
   
           shutdownSocket();
   
  +        //Synchronized section to make sure that thread
  +        //in dispose() will not hang due to race conditions
           synchronized( this )
           {
               m_thread = null;
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message