Index: TomcatAppServer.java =================================================================== RCS file: /home/eclipse/org.eclipse.tomcat/src/org/eclipse/tomcat/internal/TomcatAppServer.java,v retrieving revision 1.20 diff -u -r1.20 TomcatAppServer.java --- TomcatAppServer.java 10 Mar 2003 21:56:20 -0000 1.20 +++ TomcatAppServer.java 12 Mar 2003 18:46:29 -0000 @@ -280,7 +280,12 @@ // Remove the engine (which should trigger removing the connector) try { + Unblocker unblocker = new Unblocker(hostAddress, port); + unblocker.start(); + // The next call can sometimes block + // until a connection is made to unblock the socket embedded.removeEngine(engine); + unblocker.finish(); } catch (Exception exc) { throw new CoreException( new Status( Index: Unblocker.java =================================================================== RCS file: Unblocker.java diff -N Unblocker.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ Unblocker.java 12 Mar 2003 18:46:29 -0000 @@ -0,0 +1,71 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.tomcat.internal; + +import java.io.*; +import java.net.*; + +/** + * Periodically connects to the server + * to unblock ServerSocket.close(), that can block + * on some systems. + */ +public class Unblocker extends Thread { + private final int PERIOD = 500; + private String host; + private int port; + private boolean finishRequested = false; + public Unblocker(String host, int port) { + super(); + this.host = host; + this.port = port; + this.setName("Tomcat Unblocker"); + super.setDaemon(true); + } + + public void run() { + // server not started + if (host == null || host.length() == 0 || port == 0) { + return; + } + + while (!finishRequested) { + try { + Thread.sleep(PERIOD); + } catch (InterruptedException ie) { + } + if (finishRequested) { + break; + } + + Socket socket = null; + try { + socket = new Socket(host, port); + } catch (IOException e) { + // server closed; + return; + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException ioe) { + } + } + socket = null; + } + } + + } + + public void finish() { + finishRequested = true; + } +}