Link to home
Create AccountLog in
Avatar of komputer
komputer

asked on

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

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;
    }

Open in new window

Avatar of krishna kishore mellacheruvu venkata
krishna kishore mellacheruvu venkata
Flag of India image

Please check whether any other server running in the machine with same port.
Avatar of komputer
komputer

ASKER

i dont bind (listen) any port, i just call servlet via httpclient and i get this exception. the strange point is this.
melchkishore, i understand you, but you dont understand me (i mean my problem). the problem is a bit different, and not so easy :(
Do you get this exception on the client side or the server side?
in client side.
i am calling a servlet via apache httpclient. it is a heavy-used application so the tps is aproxcimitly is 10. normally it works fine but some intervals it throws this exception. it is very weird
which exception its throwing?
ASKER CERTIFIED SOLUTION
Avatar of komputer
komputer

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer