Sure, done. Thanks! ------------- Freeman(Yue) Fang
Red Hat, Inc. FuseSource is now part of Red Hat > On Oct 29, 2016, at 9:29 AM, Daniel Kulp <[email protected]> wrote: > > > Freeman, > > Can the timer be moved into the factory so there is a single timer for all > the conduits that the factory creates? This way still results in a timer > thread per conduit which can still balloon way up. > > Dan > > >> On Oct 28, 2016, at 7:09 PM, [email protected] wrote: >> >> Repository: cxf >> Updated Branches: >> refs/heads/3.1.x-fixes 1f61dfba7 -> 6ec0e90dc >> >> >> [CXF-7112]use Timer/TimerTask to check timeout for every async request to >> avoid create lots of thread >> >> >> Project: http://git-wip-us.apache.org/repos/asf/cxf/repo >> Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6ec0e90d >> Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6ec0e90d >> Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6ec0e90d >> >> Branch: refs/heads/3.1.x-fixes >> Commit: 6ec0e90dc12c2384612f201f54d1e6e7e7f45724 >> Parents: 1f61dfb >> Author: Freeman Fang <[email protected]> >> Authored: Sat Oct 29 07:09:39 2016 +0800 >> Committer: Freeman Fang <[email protected]> >> Committed: Sat Oct 29 07:09:39 2016 +0800 >> >> ---------------------------------------------------------------------- >> .../http/asyncclient/AsyncHTTPConduit.java | 19 ++++++++----------- >> .../http/asyncclient/AsyncHTTPConduitTest.java | 1 - >> 2 files changed, 8 insertions(+), 12 deletions(-) >> ---------------------------------------------------------------------- >> >> >> http://git-wip-us.apache.org/repos/asf/cxf/blob/6ec0e90d/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java >> ---------------------------------------------------------------------- >> diff --git >> a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java >> >> b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java >> index dba9673..bc1212f 100644 >> --- >> a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java >> +++ >> b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduit.java >> @@ -38,6 +38,8 @@ import java.security.cert.Certificate; >> import java.util.ArrayList; >> import java.util.List; >> import java.util.Map; >> +import java.util.Timer; >> +import java.util.TimerTask; >> import java.util.concurrent.Future; >> import java.util.logging.Level; >> >> @@ -106,6 +108,8 @@ public class AsyncHTTPConduit extends >> URLConnectionHTTPConduit { >> volatile SSLContext sslContext; >> volatile SSLSession session; >> volatile CloseableHttpAsyncClient client; >> + volatile Timer timer; >> + >> >> public AsyncHTTPConduit(Bus b, >> EndpointInfo ei, >> @@ -113,6 +117,7 @@ public class AsyncHTTPConduit extends >> URLConnectionHTTPConduit { >> AsyncHTTPConduitFactory factory) throws >> IOException { >> super(b, ei, t); >> this.factory = factory; >> + this.timer = new Timer(); >> } >> >> public synchronized CloseableHttpAsyncClient getHttpAsyncClient() throws >> IOException { >> @@ -642,7 +647,7 @@ public class AsyncHTTPConduit extends >> URLConnectionHTTPConduit { >> >> protected void handleResponseAsync() throws IOException { >> isAsync = true; >> - new CheckReceiveTimeoutForAsync().start(); >> + timer.schedule(new CheckReceiveTimeoutForAsync(), >> csPolicy.getReceiveTimeout()); >> } >> >> protected void closeInputStream() throws IOException { >> @@ -859,17 +864,9 @@ public class AsyncHTTPConduit extends >> URLConnectionHTTPConduit { >> } >> } >> >> - class CheckReceiveTimeoutForAsync extends Thread { >> + class CheckReceiveTimeoutForAsync extends TimerTask { >> public void run() { >> - long startTime = System.currentTimeMillis(); >> - while (httpResponse == null && exception == null >> - && (System.currentTimeMillis() - startTime) < >> csPolicy.getReceiveTimeout()) { >> - try { >> - Thread.sleep(1000); >> - } catch (InterruptedException e) { >> - throw new RuntimeException(e); >> - } >> - } >> + >> if (httpResponse == null) { >> outbuf.shutdown(); >> inbuf.shutdown(); >> >> http://git-wip-us.apache.org/repos/asf/cxf/blob/6ec0e90d/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java >> ---------------------------------------------------------------------- >> diff --git >> a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java >> >> b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java >> index fb0f78c..0c350e5 100644 >> --- >> a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java >> +++ >> b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/AsyncHTTPConduitTest.java >> @@ -139,7 +139,6 @@ public class AsyncHTTPConduitTest extends >> AbstractBusClientServerTestBase { >> HTTPConduit c = (HTTPConduit)ClientProxy.getClient(g).getConduit(); >> c.getClient().setReceiveTimeout(3000); >> try { >> - assertEquals("Hello " + request, g.greetMeLater(-5000)); >> Response<GreetMeLaterResponse> future = >> g.greetMeLaterAsync(-5000L); >> future.get(); >> fail(); >> > > -- > Daniel Kulp > [email protected] - http://dankulp.com/blog > Talend Community Coder - http://coders.talend.com >
