Implement proper multi-threading
Replace raw Thread instantiation with a thread pool.
This commit is contained in:
@@ -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.newCachedThreadPool();
|
||||||
|
|
||||||
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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user