(jersey-common=2.21.0, jackson-core=2.6.1)
How do I set http connection timeouts (connect, read) if createParser(URL url) was invoked? What is the default values used?
JsonFactory jsonF = new JsonFactory();
jsonF.enable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
JsonParser jsonP = jsonF.createParser(url); // URL instance
try {
JsonToken token;
while ( (token=jsonP.nextToken()) != null) {
if (token == JsonToken.START_OBJECT)
..rest "json sax" parser code...
}
} finally {
jsonP.close();
}
I have few times a week recurring problem when webapp stops reading json sources, task is autorun every 30 minutes. I suspect this http call stalls and starts piling up until JVM goes down.
Should I not use createParser(URL) function in production apps?
The HTTP read timeout determines how long the IBM® Watson IoT Platform - Message Gateway Web UI waits before it times out when it is waiting for an HTTP read request to complete. By default, this value is set to 20 seconds.
The default value is 100,000 milliseconds (100 seconds).
connection timeout — a time period in which a client should establish a connection with a server. socket timeout — a maximum time of inactivity between two data packets when exchanging data with a server.
You could hack the values
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
More on the settings can be found on https://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html
Or you can instead do a proper call and then pass the result into the json parser. I would go with the latter.
So to put it simply while URL is great light weight alternative I suggest switching to apache http client or some high level solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With