httpClient connection is in time_wait status in multiple threads code -


i need write code send server request consequently, request xml format string. after doing research, select use multiple threads , connection pool manager handle request , response . use poolinghttpclientconnectionmanager, httpclient 4.3 version. when use 1 thread, code works, send request , response. when make multiple thread , using single httpclient, connection seems broken. use netstat check , see tcp status time_wait. code like:

    poolinghttpclientconnectionmanager cm = new poolinghttpclientconnectionmanager();     cm.setmaxtotal(50);     cm.setdefaultmaxperroute(10);     cm.setmaxperroute(new httproute(new httphost(env_ abcd)), 20);           closeablehttpclient httpclient = httpcleints.custom().setconnectionmanager(cm).build(); 

i use thread pool too, each thread used handle 1 task (runnable). task includes generating 1 request, sending request server , getting , processing response, once task finish, thread put thread pool , connection put connection pool.

all requests sent same server far.

the runnable task includes following line code:

    httppost post = new httppost(url);     try {         // request xml string         post.setentity(new stringentity(request));     } catch (unsupportedencodingexception e1) {         e1.printstacktrace();     }     string responsestr = null;     try {         // commonhttpclient same instance of httpclient declared above.         httpresponse response = commonhttpclient.execute(post);         httpentity entity = response.getentity();         if (entity != null){             responsestr = getstring(entity.getcontent());         }      } catch (clientprotocolexception e) {         e.printstacktrace();     } catch (ioexception e) {         e.printstacktrace();     } 

i not response. can see code hanging on line of “commonhttpclient.execute(post);”. netstat, tells client side close connection.

i not have problem if there 1 thread. can tell me part of code wrong. miss step configure connection? hard find example using apache httpclient 4.3.

thanks


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -