troubleshooting Question

"java.net.BindException: Address in use" exception

Avatar of komputer
komputer asked on
Java
8 Comments1 Solution1176 ViewsLast Modified:
hi,
i have an application which makes 10 httpcall per second approximately. it was working fine but last a few days i am getting this exception;

java.net.BindException: Address in use
      at jrockit.net.SocketNativeIO.connect(ILjava/net/InetAddress;IIIZ)I(Unknown Source)
      at jrockit.net.SocketNativeIO.connect(Ljava/io/FileDescriptor;Ljava/net/InetAddress;III)I(Unknown Source)
      at java.net.AbstractSocketImpl.doConnect(Ljava/net/InetAddress;II)V(Optimized Method)
      at java.net.PlainSocketImpl.doConnect(Ljava/net/InetAddress;II)V(Unknown Source)
      at java.net.PlainSocketImpl.connectToAddress(Ljava/net/InetAddress;II)V(Unknown Source)
      at java.net.PlainSocketImpl.connect(Ljava/net/SocketAddress;I)V(Unknown Source)
      at java.net.Socket.connect(Ljava/net/SocketAddress;I)V(Optimized Method)
      at jrockit.reflect.NativeMethodInvoker.invoke0(Ljava/lang/Object;ILjava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
      at jrockit.reflect.NativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Optimized Method)
      at jrockit.reflect.VirtualNativeMethodInvoker.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Optimized Method)
      at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;I)Ljava/lang/Object;(Optimized Method)
      at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(Ljava/lang/String;Ljava/lang/String;ILjava/net/InetAddress;II)Ljava/net/Socket;(Optimized Method)
      at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(Ljava/lang/String;ILjava/net/InetAddress;ILorg/apache/commons/httpclient/params/HttpConnectionParams;)Ljava/net/Socket;(Optimized Method)
      at org.apache.commons.httpclient.HttpConnection.open()V(Optimized Method)
      at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open()V(Optimized Method)
      at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Lorg/apache/commons/httpclient/HttpMethod;)V(Optimized Method)
      at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Lorg/apache/commons/httpclient/HttpMethod;)V(Optimized Method)
      at org.apache.commons.httpclient.HttpClient.executeMethod(Lorg/apache/commons/httpclient/HostConfiguration;Lorg/apache/commons/httpclient/HttpMethod;Lorg/apache/commons/httpclient/HttpState;)I(Optimized Method)
      at com.ysnky.test.utils.HttpCall.postCallMultiThreaded(Ljava/lang/String;)Ljava/lang/String;(Optimized Method)
      at com.ysnky.test.iwis.bscs.IWISMain.sendCommand(Ljava/lang/String;)Ljava/lang/String;(Optimized Method)
      at com.ysnky.test.iwis.bscs.IwisCombinedInDetail.queryMsisdn(Ljava/lang/String;)Lcom/ysnky/test/utils/IWISResult;(Optimized Method)
      at com.ysnky.test.ejb.PrePaidTryDecAMDBBean.checkEnoughCredit(Lcom/ysnky/test/VO/TransferStateVO;)Z(Optimized Method)
      at com.ysnky.test.ejb.PrePaidTryDecAMDBBean.preDecA(Lcom/ysnky/test/VO/TransferStateVO;)V(Optimized Method)
      at com.ysnky.test.ejb.PrePaidTryDecAMDBBean.onMessage(Ljavax/jms/Message;)V(Optimized Method)
      at weblogic.ejb20.internal.MDListener.execute(Lweblogic/kernel/ExecuteThread;)V(Optimized Method)
      at weblogic.ejb20.internal.MDListener.transactionalOnMessage(Ljavax/jms/Message;)V(Optimized Method)
      at weblogic.ejb20.internal.MDListener.onMessage(Ljavax/jms/Message;)V(Optimized Method)
      at weblogic.jms.client.JMSSession.onMessage(Ljavax/jms/MessageListener;Lweblogic/jms/common/MessageImpl;)V(Optimized Method)
      at weblogic.jms.client.JMSSession.execute(Lweblogic/kernel/ExecuteThread;)V(Optimized Method)
      at weblogic.kernel.ExecuteThread.execute(Lweblogic/kernel/ExecuteRequest;)V(Optimized Method)
      at weblogic.kernel.ExecuteThread.run()V(ExecuteThread.java:183)
      at java.lang.Thread.startThreadFromVM(Ljava/lang/Thread;)V(Unknown Source)


i am using apache httpclient 3.1 with MultiThreadedHttpConnectionManager feature and my httpcall method in below.
it is very strange why i am getting this error. yes when a socket connection is setup, any port will be binded in client side too but why it is trying inused port, why it doesnt find any idle one?

thanks in advance.
public static String postCallMultiThreaded(String XML) {
        
      MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
	 	connectionManager.getParams().setDefaultMaxConnectionsPerHost(2);
		connectionManager.getParams().setMaxTotalConnections(20);
	 	HttpClient client = new HttpClient(connectionManager);
	  	
	  	client.getHttpConnectionManager().getParams().setConnectionTimeout(HTTP_CONNECTION_TIMEOUT);
		client.getHttpConnectionManager().getParams().setSoTimeout(HTTP_READ_TIMEOUT);
      String	responseBody="";
		PostMethod method = new PostMethod(URL);
		
	    // Provide custom retry handler is necessary
	    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(0, false));		    
 
	    logger.debug("postFromHttp url:" + URL);
	    try {
	        method.setRequestEntity(new StringRequestEntity(XML));
	        client.executeMethod(method);
	        if (method.getStatusCode() == HttpStatus.SC_OK) {
	            BufferedReader br = new BufferedReader(new InputStreamReader( method.getResponseBodyAsStream()));
				String line = null;
				StringBuffer respBuf = new StringBuffer();
				while ((line = br.readLine()) != null) {
				    respBuf.append(line);
				}
				responseBody = respBuf.toString();
	        }    
	    }catch (Exception e) {
	    	logger.error(e);
	    } finally {
	        method.releaseConnection();
	    }
	    
	    return responseBody;
    }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros