[jboss-cvs] JBossRemoting/src/main/org/jboss/remoting/transport/socket ...
Tom Elrod
tom.elrod at jboss.com
Wed Sep 27 13:17:33 EDT 2006
User: telrod
Date: 06/09/27 13:17:33
Modified: src/main/org/jboss/remoting/transport/socket Tag:
remoting_1_4 ServerThread.java
SocketServerInvoker.java
Log:
JBREM-409 - fixes for the 1.4 branch for socket server thread not being cleaned up (leaking). Targeted for 1.4.5.GA
Revision Changes Path
No revision
No revision
1.21.2.1 +57 -31 JBossRemoting/src/main/org/jboss/remoting/transport/socket/ServerThread.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ServerThread.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/ServerThread.java,v
retrieving revision 1.21
retrieving revision 1.21.2.1
diff -u -b -r1.21 -r1.21.2.1
--- ServerThread.java 21 Mar 2006 18:36:40 -0000 1.21
+++ ServerThread.java 27 Sep 2006 17:17:33 -0000 1.21.2.1
@@ -31,6 +31,7 @@
import java.lang.reflect.Constructor;
import java.net.Socket;
import java.net.SocketException;
+import java.net.SocketTimeoutException;
import java.util.LinkedList;
import java.util.Map;
import org.jboss.logging.Logger;
@@ -51,7 +52,7 @@
*
* @author <a href="mailto:bill at jboss.org">Bill Burke</a>
* @author <a href="mailto:tom at jboss.org">Tom Elrod</a>
- * @version $Revision: 1.21 $
+ * @version $Revision: 1.21.2.1 $
*/
public class ServerThread extends Thread
{
@@ -223,18 +224,22 @@
public synchronized void wakeup(Socket socket, int timeout, Map metadata) throws Exception
{
this.socketWrapper = createServerSocket(socket, timeout, metadata);
- String name = "SocketServerInvokerThread-" + socket.getInetAddress().getHostAddress() + "-" + nextID();
- super.setName(name);
+// String name = "SocketServerInvokerThread-" + socket.getInetAddress().getHostAddress() + "-" + nextID();
+// super.setName(name);
running = true;
handlingResponse = true;
this.notify();
+ if(log.isTraceEnabled())
+ {
+ log.trace("Have woken up " + getName());
+ }
}
public void run()
{
try
{
- while(true)
+ while (true)
{
dorun();
@@ -253,17 +258,23 @@
* it alive, resulting in a memory leak. The solution is to synchronize parts of
* ServerThread.run() and SocketServerInvoker.cleanup() so that they interact atomically.
*/
- synchronized(clientpool)
+ synchronized (this)
+ {
+ synchronized (clientpool)
{
- synchronized(threadpool)
+ synchronized (threadpool)
{
- if(shutdown)
+ if (shutdown)
{
invoker = null;
return; // exit thread
}
else
{
+ if (log.isTraceEnabled())
+ {
+ log.trace("removing from clientpool and adding to threadpool " + this);
+ }
clientpool.remove(this);
threadpool.add(this);
Thread.interrupted(); // clear any interruption so that we can be pooled.
@@ -272,13 +283,17 @@
}
}
- synchronized(this)
- {
try
{
- log.debug("begin thread wait");
+ if (log.isTraceEnabled())
+ {
+ log.trace("begin thread wait");
+ }
this.wait();
- log.debug("WAKEUP in SERVER THREAD");
+ if (log.isTraceEnabled())
+ {
+ log.trace("WAKEUP in SERVER THREAD");
+ }
}
catch (InterruptedException e)
{
@@ -293,7 +308,7 @@
}
}
}
- catch(Exception ignored)
+ catch (Exception ignored)
{
log.debug("Exiting run on exception", ignored);
}
@@ -340,7 +355,7 @@
//TODO: -TME Need better way to get the unmarshaller (via config)
UnMarshaller unmarshaller = MarshalFactory.getUnMarshaller(invoker.getLocator(), this.getClass().getClassLoader());
- if(unmarshaller == null)
+ if (unmarshaller == null)
{
unmarshaller = MarshalFactory.getUnMarshaller(invoker.getDataType(), invoker.getSerializationType());
}
@@ -363,7 +378,7 @@
}
*/
}
- catch(Exception ex)
+ catch (Exception ex)
{
resp = ex;
}
@@ -372,7 +387,7 @@
Marshaller marshaller = MarshalFactory.getMarshaller(invoker.getLocator(), this.getClass().getClassLoader());
- if(marshaller == null)
+ if (marshaller == null)
{
marshaller = MarshalFactory.getMarshaller(invoker.getDataType(), invoker.getSerializationType());
}
@@ -420,6 +435,17 @@
running = false;
}
+ catch(SocketTimeoutException ste)
+ {
+ if(!shutdown)
+ {
+ if(log.isTraceEnabled())
+ {
+ log.trace(ste);
+ }
+ }
+ running = false;
+ }
catch(InterruptedIOException e)
{
if(!shutdown)
1.19.2.2 +32 -8 JBossRemoting/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SocketServerInvoker.java
===================================================================
RCS file: /cvsroot/jboss/JBossRemoting/src/main/org/jboss/remoting/transport/socket/SocketServerInvoker.java,v
retrieving revision 1.19.2.1
retrieving revision 1.19.2.2
diff -u -b -r1.19.2.1 -r1.19.2.2
--- SocketServerInvoker.java 28 Mar 2006 07:14:03 -0000 1.19.2.1
+++ SocketServerInvoker.java 27 Sep 2006 17:17:33 -0000 1.19.2.2
@@ -42,7 +42,7 @@
*
* @author <a href="mailto:jhaynie at vocalocity.net">Jeff Haynie</a>
* @author <a href="mailto:tom.elrod at jboss.com">Tom Elrod</a>
- * @version $Revision: 1.19.2.1 $
+ * @version $Revision: 1.19.2.2 $
* @jmx:mbean
*/
public class SocketServerInvoker extends ServerInvoker implements Runnable, SocketServerInvokerMBean
@@ -73,6 +73,8 @@
protected LRUPool clientpool;
protected LinkedList threadpool;
+ protected boolean reuseAddress = true;
+
/**
* The logging trace level flag
*/
@@ -134,6 +136,7 @@
try
{
serverSocket = createServerSocket(getServerBindPort(), backlog, bindAddress);
+ serverSocket.setReuseAddress(reuseAddress);
}
catch(IOException e)
{
@@ -280,6 +283,27 @@
}
/**
+ * Indicates if SO_REUSEADDR is enabled on server sockets
+ * Default is true.
+ * @return
+ */
+ public boolean getReuseAddress()
+ {
+ return reuseAddress;
+ }
+
+ /**
+ * Sets if SO_REUSEADDR is enabled on server sockets.
+ * Default is true.
+ *
+ * @param reuse
+ */
+ public void setReuseAddress(boolean reuse)
+ {
+ this.reuseAddress = reuse;
+ }
+
+ /**
* @return Value of property serverBindPort.
* @jmx:managed-attribute
*/
More information about the jboss-cvs-commits
mailing list