From 0dd9e8ce022d2dce6d612ba52681ac97fdc39d4e Mon Sep 17 00:00:00 2001 From: Sebastien Deleuze Date: Thu, 16 Aug 2018 21:04:23 +0200 Subject: [PATCH] Polish JettyResourceFactory Issue: SPR-17179 --- .../client/reactive/JettyResourceFactory.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java index 1afbb1ba3a..5af0b28f2f 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java @@ -23,7 +23,7 @@ import java.util.concurrent.Executor; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.util.ProcessorUtils; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.Scheduler; @@ -127,7 +127,6 @@ public class JettyResourceFactory implements InitializingBean, DisposableBean { if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); - threadPool.start(); this.executor = threadPool; } if (this.byteBufferPool == null) { @@ -137,19 +136,32 @@ public class JettyResourceFactory implements InitializingBean, DisposableBean { : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { - Scheduler scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); - scheduler.start(); - this.scheduler = scheduler; + this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } + + if (this.executor instanceof LifeCycle) { + ((LifeCycle)this.executor).start(); + } + this.scheduler.start(); } @Override public void destroy() throws Exception { - if (this.executor instanceof ContainerLifeCycle) { - ((ContainerLifeCycle)this.executor).stop(); + try { + if (this.executor instanceof LifeCycle) { + ((LifeCycle)this.executor).stop(); + } + } + catch (Throwable ex) { + // ignore + } + try { + if (this.scheduler != null) { + this.scheduler.stop(); + } } - if (this.scheduler != null) { - this.scheduler.stop(); + catch (Throwable ex) { + // ignore } } -- GitLab