multithreading - In Java, thread hangs in SocketRead0, what can I do? -
i'm developing webcrawler, after short time executing (minutes), threads stop work. running debugger, found stop in socketread0.
this occurs when thread download content of page httpurlconnection.getinputstream()
.
i don't know causes this, think associated multithreading.
someone knows how solve or avoid this?
i'm not using pool of httpurlconnection yet beucase don't know how do.
conn = (httpurlconnection) new url(url).openconnection(); conn.setinstancefollowredirects(true); conn.connect(); countinginputstream content; try { content = new countinginputstream(conn.getinputstream()); //processing of content content.close(); return true; } catch (exception e) { return false; }
you need set socket read timeout on connection. cause throw exception instead of hanging after specified time period.
http://download.oracle.com/javase/1.5.0/docs/api/java/net/urlconnection.html#setreadtimeout(int)
Comments
Post a Comment