java - URLConnection getting stuck and not throwing errors -
below code. when run code gets stuck. runs loop 100 times 3000. weird is not throw error gets stuck. have ideas?
import java.io.ioexception; import java.util.logging.level; import java.util.logging.logger; import us.monoid.web.resty; public class example1 { /** * @param args command line arguments */ public static void main(string[] args) { // allow certificates - see http://en.wikibooks.org/wiki/programming:webobjects/web_services/how_to_trust_any_ssl_certificate sslutilities.trustallhostnames( ); sslutilities.trustallhttpscertificates() ; // variables int = 0; string askbidurl = "https://www.exchangebitcoins.com/data/depth"; while(true){ system.out.println("example 1 - run #" + i); resty r = new resty(); try {string jsonw = r.text(askbidurl).tostring();} catch (ioexception ex){logger.getlogger(example1.class.getname()).log(level.severe, null, ex); } i++; } } }
resty.text() or invocation therein might not taking data in fast enough.
i've had happen when performing read() operation httpurlconnection's inputstream (even bufferedinputstream in middle) , appending bytes gradually string. apparently caused string being built , not keeping incoming data. optimizing loop problem went away.
it happen randomly, once in 100 1000 gets; when happened somehow sabotage later connections, if outside timer thread close()d stuck read()'s streams , connection.
speculatively, seems transfer sort of gives if loop doesn't eat data inputstream fast enough, inputstream's read() never sees zero-sized block , never finishes.
not sure how of mood you're in modify library...
Comments
Post a Comment