commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Allen, Michael B (RSCH)" <>
Subject RE: httpclient hangs indefinately
Date Sun, 03 Feb 2002 23:16:01 GMT

> -----Original Message-----
> From:	Ludwig, Sven [SMTP:SLudwig@CONET.DE]
> I read about that issue of blocking IO in the constructors
> of with JDKs up to 1.3 some time ago on
> It was easy to find the article again:
> Along with it there is an implementation "TimedSocket" available: 
> (seperate thread that interrupts the connection attempts)
	Actually, the separate thread trys to do the connect while the caller sits there
	polling isConnected(). It does not "interrupt" the other thread (I have actually
	tried that and it doesn't work). Regardless, the idea behind this article is a good
	idea but it's a very poor inplementation. It would have been trivial to just do
	something like:

	public class TimedSocket() extends Thread {

		String host;
		int port;
		IOException e;
		Socket s;

		TimedSocket( host, port, long timeout ) IOException { = host;
			this.port = port;
			e = null;
			synchronized( this ) {
				wait( timeout );
			if (e == null) {
				throw e;

		public void run() {
			synchronized( this ) {
				try {
					s = new Socket( host, port );			
				} catch( IOException ioe ) {
					e = ioe;

	Although I don't know about the synchronized( this ) in a constructor. That
	might be better off elsewhere. Also, the new Socket call will still be blocked
	long after the TimedSocket has thrown the IOException. Under certain
	conditions it's concievable that the application could just consume dozens of
	hung sockets running the app into memory overload.

	It's a good alternative if you don't have JDK 1.4's Socket constructors with the
	timeout parameter. Unfortunately for me I cannot use it because it creates an
	extra thread for every connection which under certain conditions would be an
	inappropriate way to deal with this rare Socket timeout corner case issue.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message