Implement proper multi-threading

Replace raw Thread instantiation with a thread pool.
This commit is contained in:
A248 2019-11-23 10:56:28 -05:00 committed by GitHub
parent b5621816cb
commit f2bc472f6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -20,9 +20,10 @@ import java.util.Scanner;
public class MineSkinFetcher {
private static final String MINESKIN_API = "https://api.mineskin.org/get/id/";
private static final ExecutorService threadPool = Executors.newCachedThreadPool();
public static void fetchSkinFromIdAsync(int id, Callback callback) {
new Thread(() -> {
threadPool.execute(() -> {
try {
StringBuilder builder = new StringBuilder();
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(MINESKIN_API + id).openConnection();
@ -50,7 +51,7 @@ public class MineSkinFetcher {
exception.printStackTrace();
callback.failed();
}
}).start();
});
}
public interface Callback {