From: David ‘Bombe’ Roden Date: Fri, 6 May 2011 21:50:51 +0000 (+0200) Subject: Use a thread pool to download Sones. X-Git-Tag: 0.6.4^2~15 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=a7bd72e4db218681c02e7115f743e91b31af28e9 Use a thread pool to download Sones. This fixes #192. --- diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 53b6700..238d9d5 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.Map.Entry; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.logging.Level; import java.util.logging.Logger; @@ -107,6 +109,9 @@ public class Core implements IdentityListener, UpdateListener { /** The Sone downloader. */ private final SoneDownloader soneDownloader; + /** Sone downloader thread-pool. */ + private final ExecutorService soneDownloaders = Executors.newFixedThreadPool(10); + /** The update checker. */ private final UpdateChecker updateChecker; @@ -919,7 +924,7 @@ public class Core implements IdentityListener, UpdateListener { remoteSones.put(identity.getId(), sone); soneDownloader.addSone(sone); setSoneStatus(sone, SoneStatus.unknown); - new Thread(new Runnable() { + soneDownloaders.execute(new Runnable() { @Override @SuppressWarnings("synthetic-access") @@ -927,7 +932,7 @@ public class Core implements IdentityListener, UpdateListener { soneDownloader.fetchSone(sone, sone.getRequestUri()); } - }, "Sone Downloader").start(); + }); return sone; } }