Skip to content

Commit

Permalink
Avoid continual thread replacement in JarCacheSupport (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jan 9, 2024
1 parent 399fb9b commit b15dcf7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/java/hudson/remoting/JarCacheSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -40,10 +44,17 @@ public abstract class JarCacheSupport extends JarCache {
/**
* Throttle the jar downloading activity so that it won't eat up all the channel bandwidth.
*/
private final ExecutorService downloader = new AtmostOneThreadExecutor(
private final ExecutorService downloader = newCachingSingleThreadExecutor(
new NamingThreadFactory(new DaemonThreadFactory(), JarCacheSupport.class.getSimpleName())
);

private static ExecutorService newCachingSingleThreadExecutor(ThreadFactory threadFactory) {
ThreadPoolExecutor threadPoolExecutor =
new ThreadPoolExecutor(1, 1, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), threadFactory);
threadPoolExecutor.allowCoreThreadTimeOut(true);
return threadPoolExecutor;
}

@Override
@NonNull
public CompletableFuture<URL> resolve(@NonNull final Channel channel, final long sum1, final long sum2) throws IOException, InterruptedException {
Expand Down

0 comments on commit b15dcf7

Please sign in to comment.