From 1881e48bb4f5643a0dbdfa6f24a5e0fb055274f6 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 14 Jun 2022 10:59:02 +0200 Subject: [PATCH] Remove Jetty dependencies from JdkHttpClientResourceFactory This commit removes the Eclipse Jetty dependencies from JdkHttpClientResourceFactory, replacing them with a check for ExecutorService. Closes gh-28588 --- .../JdkHttpClientResourceFactory.java | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java index 956c411c0fc..f46fd8494ad 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,12 +18,10 @@ package org.springframework.http.client.reactive; import java.net.http.HttpClient; import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; -import org.eclipse.jetty.util.component.LifeCycle; -import org.eclipse.jetty.util.thread.QueuedThreadPool; - import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.lang.Nullable; @@ -70,10 +68,10 @@ public class JdkHttpClientResourceFactory implements InitializingBean, Disposabl } /** - * Configure the thread prefix to initialize {@link QueuedThreadPool} executor with. This + * Configure the thread prefix to initialize the executor with. This * is used only when a {@link Executor} instance isn't * {@link #setExecutor(Executor) provided}. - *

By default set to "jetty-http". + *

By default set to "jdk-http". * @param threadPrefix the thread prefix to use */ public void setThreadPrefix(String threadPrefix) { @@ -88,20 +86,12 @@ public class JdkHttpClientResourceFactory implements InitializingBean, Disposabl String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); this.executor = Executors.newCachedThreadPool(new CustomizableThreadFactory(name)); } - if (this.executor instanceof LifeCycle) { - ((LifeCycle)this.executor).start(); - } } @Override public void destroy() throws Exception { - try { - if (this.executor instanceof LifeCycle) { - ((LifeCycle)this.executor).stop(); - } - } - catch (Throwable ex) { - // ignore + if (this.executor instanceof ExecutorService executorService) { + executorService.shutdown(); } }