servlets - Random occurrences of java.net.ConnectException -


i'm experiencing java.net.connectexception in random ways.

my servlet runs in tomcat 6.0 (jdk 1.6). servlet periodically fetches data 4-5 third-party web servers. servlet uses scheduledexecutorservice fetch data.

run locally, fine , dandy. run on prod server, see semi-random failures fetch data 1 of third parties (canadian weather data).

these urls failing (plain rss feeds):

strange: each cycle, when periodically fetch data, success/fail on map: some succeed, fail, never seems same twice. so, i'm not blocked, randomly blocked.

i slowed down fetches, introducing 61s pause between each one. had no effect.

the guts of code actual fetch:

  private static final int timeout = 60*1000; //msecs    public string fetch(string aurl, string aencoding /*utf-8*/) {     string result = "";     long start = system.currenttimemillis();     scanner scanner = null;     urlconnection connection = null;     try {       url url = new url(aurl);       connection =  url.openconnection(); //this doesn't talk network yet       connection.setconnecttimeout(timeout);        connection.setreadtimeout(timeout);       connection.connect(); //actually connects; shouldn't needed here       scanner = new scanner(connection.getinputstream(), aencoding);        scanner.usedelimiter(end_of_input);       result = scanner.next();     }     catch (ioexception ex) {       long end = system.currenttimemillis();       long time = end - start;       flogger.severe(         "problem connecting " + aurl + " encoding:" + aencoding +          ". exception: " + ex.getmessage() + " " + ex.tostring() + " cause:" +  ex.getcause() +          " connection timeout: " + connection.getconnecttimeout() + "msecs. read timeout:" +          connection.getreadtimeout() + "msecs."         + " time taken fail: " + time + " msecs."       );     }     {       if (scanner != null) scanner.close();     }     return result;   } 

example log entry showing failure:

severe: problem connecting http://weather.gc.ca/rss/city/pe-5_e.xml encoding:utf-8.  exception: connection timed out java.net.connectexception: connection timed out  cause:null  connection timeout: 60000msecs.  read timeout:60000msecs.  time taken fail: 15028 msecs.   

note time fail 15s + tiny amount. note fails reach configured 60s timeout connection.

the host-server admins (environment canada) state don't have kind of blacklist ip address of misbehaving clients.

also important: code had been running several months without happening.

someone suggested instead should use curl, bash script, , cron. implemented that, , works fine.

i'm not able solve problem using java.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -