Below is my code. When I run this code it always gets stuck. Sometimes it runs the loop 100 times sometimes 3000. What is weird is that is does not throw an error it just gets stuck. Anybody have any 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 the 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 i = 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 an invocation therein might not be taking the data in fast enough.
I’ve had something like this happen when performing a read() operation from an HTTPURLConnection’s InputStream (even with a BufferedInputStream in the middle) and appending the bytes gradually to a String. It apparently was caused by the String being built too slowly and not keeping up with the incoming data. By optimizing that loop the problem went away.
It would happen randomly, about once in 100 to 1000 GETs; but when it happened it would somehow sabotage later connections, even if an outside timer thread close()d the stuck read()’s streams and connection.
Speculatively, it seems that the transfer sort of gives up sometimes if the loop doesn’t eat the data from the InputStream fast enough, so the InputStream’s read() never sees the zero-sized block and never finishes.
Not sure how much of a mood you’re in to modify your library…