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
commit a6667129c9
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.newSingleThreadExecutor();
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 {