From 0b6dde00822d9ce2d63847c1f150d54fde5a9768 Mon Sep 17 00:00:00 2001 From: Lucas Pouzac Date: Mon, 11 Aug 2014 13:29:18 +0200 Subject: [PATCH] HTTPCLIENT-1538 : monitor contention --- .../client/CloseableHttpResponseProxy.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java b/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java index 5b575f636c..508de603b1 100644 --- a/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java +++ b/httpclient/src/main/java/org/apache/http/impl/client/CloseableHttpResponseProxy.java @@ -28,6 +28,7 @@ package org.apache.http.impl.client; import java.io.IOException; +import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -45,6 +46,17 @@ @NotThreadSafe class CloseableHttpResponseProxy implements InvocationHandler { + private static Constructor ctor; + + static { + try { + ctor = Proxy.getProxyClass(CloseableHttpResponseProxy.class.getClassLoader(), + new Class[] { CloseableHttpResponse.class }).getConstructor(new Class[] { InvocationHandler.class }); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + private final HttpResponse original; CloseableHttpResponseProxy(final HttpResponse original) { @@ -78,10 +90,11 @@ public Object invoke( } public static CloseableHttpResponse newProxy(final HttpResponse original) { - return (CloseableHttpResponse) Proxy.newProxyInstance( - CloseableHttpResponseProxy.class.getClassLoader(), - new Class[] { CloseableHttpResponse.class }, - new CloseableHttpResponseProxy(original)); + try { + return (CloseableHttpResponse) ctor.newInstance(new CloseableHttpResponseProxy(original)); + } catch (Exception e) { + throw new RuntimeException(e); + } } }