Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 36508 invoked from network); 19 Dec 2007 19:50:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Dec 2007 19:50:40 -0000 Received: (qmail 23187 invoked by uid 500); 19 Dec 2007 19:50:24 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 23165 invoked by uid 500); 19 Dec 2007 19:50:24 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 23152 invoked by uid 99); 19 Dec 2007 19:50:24 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 11:50:24 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Dec 2007 19:50:08 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 84F451A9832; Wed, 19 Dec 2007 11:50:12 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r605671 - /activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java Date: Wed, 19 Dec 2007 19:50:12 -0000 To: commits@activemq.apache.org From: rajdavies@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071219195012.84F451A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rajdavies Date: Wed Dec 19 11:50:11 2007 New Revision: 605671 URL: http://svn.apache.org/viewvc?rev=605671&view=rev Log: close socket in a separate thread and only await stopLatch for 2 seconds - as it close could be called by InactivityMonitor Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java?rev=605671&r1=605670&r2=605671&view=diff ============================================================================== --- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java (original) +++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/transport/tcp/TcpTransport.java Wed Dec 19 11:50:11 2007 @@ -30,6 +30,10 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.net.SocketFactory; @@ -50,7 +54,7 @@ */ public class TcpTransport extends TransportThreadSupport implements Transport, Service, Runnable { private static final Log LOG = LogFactory.getLog(TcpTransport.class); - + private static final ThreadPoolExecutor SOCKET_CLOSE; protected final URI remoteLocation; protected final URI localLocation; protected final WireFormat wireFormat; @@ -427,7 +431,23 @@ // is hung.. then this hangs the close. // closeStreams(); if (socket != null) { - socket.close(); + //closing the socket can hang also + final CountDownLatch latch = new CountDownLatch(1); + SOCKET_CLOSE.execute(new Runnable() { + + public void run() { + try { + socket.close(); + } catch (IOException e) { + LOG.debug("Caught exception closing socket",e); + }finally { + latch.countDown(); + } + } + + }); + latch.await(1,TimeUnit.SECONDS); + } } @@ -439,7 +459,7 @@ super.stop(); CountDownLatch countDownLatch = stoppedLatch.get(); if (countDownLatch != null && Thread.currentThread() != this.runnerThread) { - countDownLatch.await(); + countDownLatch.await(1,TimeUnit.SECONDS); } } @@ -478,4 +498,13 @@ return super.narrow(target); } + static { + SOCKET_CLOSE = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 10, TimeUnit.SECONDS, new SynchronousQueue(), new ThreadFactory() { + public Thread newThread(Runnable runnable) { + Thread thread = new Thread(runnable, "TcpSocketClose: "+runnable); + thread.setDaemon(true); + return thread; + } + }); + } }