Hello,

I have just switched http components from 4.2 to 4.3 and I'm experiencing a change in behavior.

I'm using something like:

        Future<HttpResponse> f = httpClient.execute(httpRequest, callback);
        if (async) {
            return;
        }

        HttpResponse resp = f.get();
        ...

where callback implements FutureCallback<HttpResponse>

With 4.2, the completed()/failed()/cancelled() method would be called first and f.get() would not return until it was done. With 4.3, the f.get() method returns before or in the middle of the completed() method, which totally defies the purpose of using f.get().

I have tracked down this behavior change to a commit in BasicFuture.java. In 4.2, the whole completed() method was synchronized:

        public synchronized boolean completed(final T result) {
            if (this.completed) {
                return false;
            }
            this.completed = true;
            this.result = result;
            if (this.callback != null) {
                this.callback.completed(result);
            }
            notifyAll();
            return true;
        }

As a consequence, the notifyAll() method is called only after callback.completed() is called

In 4.3 though, only a portion of the method is synchronized:

        public boolean completed(final T result) {
        synchronized(this) {
            if (this.completed) {
                return false;
            }
            this.completed = true;
            this.result = result;
            notifyAll();
        }
        if (this.callback != null) {
            this.callback.completed(result);
        }
        return true;
    }
It then becomes possible for the get() method (which is also synchronized on this) to return before this.callback.completed to be called.

Or did I misunderstood the use of the get() method ?

Thanks,

Arnaud Quillaud

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to