soap - Java: Waiting connection threads created by HTTP connection are alive for very long duration -


i have server side code checks if soap service up. code looks like:

string response = "";  while (response.length() == 0) {     try {         final url url = new url("dummysoapserviceurl");         final httpurlconnection httpconnection = (httpurlconnection) url.openconnection();         inputstream inputstream = null;         try {             httpconnection.setrequestmethod("get");              inputstream = httpconnection.getinputstream();             final byte[] buffer = new byte[buffer_size];             while (inputstream.read(buffer, 0, buffer_size) != -1) {                 response = new string(buffer);             }         } {             ioutils.closequietly(inputstream);             httpconnection.disconnect();         }     } catch (malformedurlexception e) {         // error handling     } catch (ioexception e) {         // error handling     } } 

now problem that, every check around 3-4 connection threads created. , these threads alive if soap service check completed. snapshot of thread dump, these threads looks like:

"http-host/ip:port-11" prio=10 tid=0x00000000064f0000 nid=0x32cc waiting on condition [0x00002b54bc604000]    java.lang.thread.state: waiting (parking)     @ sun.misc.unsafe.park(native method)     - parking wait  <0x00000000d5093c78> (a java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject)     @ java.util.concurrent.locks.locksupport.park(locksupport.java:186)     @ java.util.concurrent.locks.abstractqueuedsynchronizer$conditionobject.await(abstractqueuedsynchronizer.java:2043)     @ java.util.concurrent.linkedblockingqueue.take(linkedblockingqueue.java:442)     @ java.util.concurrent.threadpoolexecutor.gettask(threadpoolexecutor.java:1068)     @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1130)     @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615)     @ org.apache.tomcat.util.net.nioendpoint$defaultthreadfactory$1$1.run(nioendpoint.java:1249)     @ java.lang.thread.run(thread.java:744)    locked ownable synchronizers:     - none 

now not sure why these connections threads waiting/parking , how close them. in code opened streams closed , connections disconnected using disconnect().

i tried set following http property:

httpconnection.addrequestproperty("connection", "close"); 

but didn't help. doubt @ time java might closing these threads. don't know, when , how? jdk version jdk1.7.0_51_x64. please let me know, how can stop these connection thread numbers building up?

migrated whole implementation use apache http client has special apis better control. didn't help. apache http client, see these waiting connection threads.

finally found hint on redhat website jboss http connector configuration. configured thread pool http connector , solved issue:

<subsystem xmlns="urn:jboss:domain:threads:1.1">      <thread-factory name="http-connector-factory" group-name="uq-thread-pool" thread-name-pattern="http-%t" priority="9"/>      <unbounded-queue-thread-pool name="uq-thread-pool">          <max-threads count="5"/>          <keepalive-time time="5" unit="seconds"/>          <thread-factory name="http-connector-factory"/>      </unbounded-queue-thread-pool>  </subsystem>   <subsystem xmlns="urn:jboss:domain:web:2.2" default-virtual-server="default-host" native="false">      <connector name="http" protocol="org.apache.coyote.http11.http11nioprotocol" scheme="http" socket-binding="http" executor="uq-thread-pool"/>      ....     .... 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -