Skip to content

Commit 0dd9e8c

Browse files
committed
Polish JettyResourceFactory
Issue: SPR-17179
1 parent 6bcb454 commit 0dd9e8c

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import org.eclipse.jetty.io.ByteBufferPool;
2424
import org.eclipse.jetty.io.MappedByteBufferPool;
2525
import org.eclipse.jetty.util.ProcessorUtils;
26-
import org.eclipse.jetty.util.component.ContainerLifeCycle;
26+
import org.eclipse.jetty.util.component.LifeCycle;
2727
import org.eclipse.jetty.util.thread.QueuedThreadPool;
2828
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
2929
import org.eclipse.jetty.util.thread.Scheduler;
@@ -127,7 +127,6 @@ public void afterPropertiesSet() throws Exception {
127127
if (this.executor == null) {
128128
QueuedThreadPool threadPool = new QueuedThreadPool();
129129
threadPool.setName(name);
130-
threadPool.start();
131130
this.executor = threadPool;
132131
}
133132
if (this.byteBufferPool == null) {
@@ -137,19 +136,32 @@ public void afterPropertiesSet() throws Exception {
137136
: ProcessorUtils.availableProcessors() * 2);
138137
}
139138
if (this.scheduler == null) {
140-
Scheduler scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false);
141-
scheduler.start();
142-
this.scheduler = scheduler;
139+
this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false);
143140
}
141+
142+
if (this.executor instanceof LifeCycle) {
143+
((LifeCycle)this.executor).start();
144+
}
145+
this.scheduler.start();
144146
}
145147

146148
@Override
147149
public void destroy() throws Exception {
148-
if (this.executor instanceof ContainerLifeCycle) {
149-
((ContainerLifeCycle)this.executor).stop();
150+
try {
151+
if (this.executor instanceof LifeCycle) {
152+
((LifeCycle)this.executor).stop();
153+
}
154+
}
155+
catch (Throwable ex) {
156+
// ignore
157+
}
158+
try {
159+
if (this.scheduler != null) {
160+
this.scheduler.stop();
161+
}
150162
}
151-
if (this.scheduler != null) {
152-
this.scheduler.stop();
163+
catch (Throwable ex) {
164+
// ignore
153165
}
154166
}
155167

0 commit comments

Comments
 (0)