Merge pull request #47 from A248/master

Implement proper multi-threading
This commit is contained in:
Jitse Boonstra
2019-12-30 18:16:25 +01:00
committed by GitHub
@@ -20,9 +20,10 @@ import java.util.Scanner;
public class MineSkinFetcher { public class MineSkinFetcher {
private static final String MINESKIN_API = "https://api.mineskin.org/get/id/"; private static final String MINESKIN_API = "https://api.mineskin.org/get/id/";
private static final ExecutorService threadPool = Executors.newSingleThreadExecutor();
public static void fetchSkinFromIdAsync(int id, Callback callback) { public static void fetchSkinFromIdAsync(int id, Callback callback) {
new Thread(() -> { threadPool.execute(() -> {
try { try {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(MINESKIN_API + id).openConnection(); HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(MINESKIN_API + id).openConnection();
@@ -50,7 +51,7 @@ public class MineSkinFetcher {
exception.printStackTrace(); exception.printStackTrace();
callback.failed(); callback.failed();
} }
}).start(); });
} }
public interface Callback { public interface Callback {