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(I Ljava/net/ InetAddres s;IIIZ)I(U nknown Source)
at jrockit.net.SocketNativeIO .connect(L java/io/Fi leDescript or;Ljava/n et/InetAdd ress;III)I (Unknown Source)
at java.net.AbstractSocketImp l.doConnec t(Ljava/ne t/InetAddr ess;II)V(O ptimized Method)
at java.net.PlainSocketImpl.d oConnect(L java/net/I netAddress ;II)V(Unkn own Source)
at java.net.PlainSocketImpl.c onnectToAd dress(Ljav a/net/Inet Address;II )V(Unknown Source)
at java.net.PlainSocketImpl.c onnect(Lja va/net/Soc ketAddress ;I)V(Unkno wn Source)
at java.net.Socket.connect(Lj ava/net/So cketAddres s;I)V(Opti mized Method)
at jrockit.reflect.NativeMeth odInvoker. invoke0(Lj ava/lang/O bject;ILja va/lang/Ob ject;[Ljav a/lang/Obj ect;)Ljava /lang/Obje ct;(Unknow n Source)
at jrockit.reflect.NativeMeth odInvoker. invoke(Lja va/lang/Ob ject;[Ljav a/lang/Obj ect;)Ljava /lang/Obje ct;(Optimi zed Method)
at jrockit.reflect.VirtualNat iveMethodI nvoker.inv oke(Ljava/ lang/Objec t;[Ljava/l ang/Object ;)Ljava/la ng/Object; (Optimized Method)
at java.lang.reflect.Method.i nvoke(Ljav a/lang/Obj ect;[Ljava /lang/Obje ct;I)Ljava /lang/Obje ct;(Optimi zed Method)
at org.apache.commons.httpcli ent.protoc ol.Reflect ionSocketF actory.cre ateSocket( Ljava/lang /String;Lj ava/lang/S tring;ILja va/net/Ine tAddress;I I)Ljava/ne t/Socket;( Optimized Method)
at org.apache.commons.httpcli ent.protoc ol.Default ProtocolSo cketFactor y.createSo cket(Ljava /lang/Stri ng;ILjava/ net/InetAd dress;ILor g/apache/c ommons/htt pclient/pa rams/HttpC onnectionP arams;)Lja va/net/Soc ket;(Optim ized Method)
at org.apache.commons.httpcli ent.HttpCo nnection.o pen()V(Opt imized Method)
at org.apache.commons.httpcli ent.MultiT hreadedHtt pConnectio nManager$H ttpConnect ionAdapter .open()V(O ptimized Method)
at org.apache.commons.httpcli ent.HttpMe thodDirect or.execute WithRetry( Lorg/apach e/commons/ httpclient /HttpMetho d;)V(Optim ized Method)
at org.apache.commons.httpcli ent.HttpMe thodDirect or.execute Method(Lor g/apache/c ommons/htt pclient/Ht tpMethod;) V(Optimize d Method)
at org.apache.commons.httpcli ent.HttpCl ient.execu teMethod(L org/apache /commons/h ttpclient/ HostConfig uration;Lo rg/apache/ commons/ht tpclient/H ttpMethod; Lorg/apach e/commons/ httpclient /HttpState ;)I(Optimi zed Method)
at com.ysnky.test.utils.HttpC all.postCa llMultiThr eaded(Ljav a/lang/Str ing;)Ljava /lang/Stri ng;(Optimi zed Method)
at com.ysnky.test.iwis.bscs.I WISMain.se ndCommand( Ljava/lang /String;)L java/lang/ String;(Op timized Method)
at com.ysnky.test.iwis.bscs.I wisCombine dInDetail. queryMsisd n(Ljava/la ng/String; )Lcom/ysnk y/test/uti ls/IWISRes ult;(Optim ized Method)
at com.ysnky.test.ejb.PrePaid TryDecAMDB Bean.check EnoughCred it(Lcom/ys nky/test/V O/Transfer StateVO;)Z (Optimized Method)
at com.ysnky.test.ejb.PrePaid TryDecAMDB Bean.preDe cA(Lcom/ys nky/test/V O/Transfer StateVO;)V (Optimized Method)
at com.ysnky.test.ejb.PrePaid TryDecAMDB Bean.onMes sage(Ljava x/jms/Mess age;)V(Opt imized Method)
at weblogic.ejb20.internal.MD Listener.e xecute(Lwe blogic/ker nel/Execut eThread;)V (Optimized Method)
at weblogic.ejb20.internal.MD Listener.t ransaction alOnMessag e(Ljavax/j ms/Message ;)V(Optimi zed Method)
at weblogic.ejb20.internal.MD Listener.o nMessage(L javax/jms/ Message;)V (Optimized Method)
at weblogic.jms.client.JMSSes sion.onMes sage(Ljava x/jms/Mess ageListene r;Lweblogi c/jms/comm on/Message Impl;)V(Op timized Method)
at weblogic.jms.client.JMSSes sion.execu te(Lweblog ic/kernel/ ExecuteThr ead;)V(Opt imized Method)
at weblogic.kernel.ExecuteThr ead.execut e(Lweblogi c/kernel/E xecuteRequ est;)V(Opt imized Method)
at weblogic.kernel.ExecuteThr ead.run()V (ExecuteTh read.java: 183)
at java.lang.Thread.startThre adFromVM(L java/lang/ Thread;)V( Unknown Source)
i am using apache httpclient 3.1 with MultiThreadedHttpConnectio nManager 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.
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
at jrockit.net.SocketNativeIO
at java.net.AbstractSocketImp
at java.net.PlainSocketImpl.d
at java.net.PlainSocketImpl.c
at java.net.PlainSocketImpl.c
at java.net.Socket.connect(Lj
at jrockit.reflect.NativeMeth
at jrockit.reflect.NativeMeth
at jrockit.reflect.VirtualNat
at java.lang.reflect.Method.i
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at com.ysnky.test.utils.HttpC
at com.ysnky.test.iwis.bscs.I
at com.ysnky.test.iwis.bscs.I
at com.ysnky.test.ejb.PrePaid
at com.ysnky.test.ejb.PrePaid
at com.ysnky.test.ejb.PrePaid
at weblogic.ejb20.internal.MD
at weblogic.ejb20.internal.MD
at weblogic.ejb20.internal.MD
at weblogic.jms.client.JMSSes
at weblogic.jms.client.JMSSes
at weblogic.kernel.ExecuteThr
at weblogic.kernel.ExecuteThr
at java.lang.Thread.startThre
i am using apache httpclient 3.1 with MultiThreadedHttpConnectio
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;
}
Please check whether any other server running in the machine with same port.
ASKER
i dont bind (listen) any port, i just call servlet via httpclient and i get this exception. the strange point is this.
please find the following link i think it may solve your problem
https://www.experts-exchange.com/questions/20793476/java-net-BindException-Address-in-use-bind-error.html?sfQueryTermInfo=1+java.net.bindexcept
https://www.experts-exchange.com/questions/20793476/java-net-BindException-Address-in-use-bind-error.html?sfQueryTermInfo=1+java.net.bindexcept
ASKER
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?
ASKER
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
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
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.