mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-13 19:34:02 +00:00
Tweak thread pool
This commit is contained in:
3 files changed
+18
-7
No files matched your search
@@ -2,9 +2,7 @@ package customskinloader;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
@@ -54,7 +52,20 @@ public class CustomSkinLoader {
|
||||
private static final ProfileCache profileCache=new ProfileCache();
|
||||
private static final DynamicSkullManager dynamicSkullManager=new DynamicSkullManager();
|
||||
|
||||
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue<>());
|
||||
//Correct thread name in thread pool
|
||||
private static final ThreadFactory defaultFactory = Executors.defaultThreadFactory();
|
||||
private static final ThreadFactory customFactory = r -> {
|
||||
Thread t = defaultFactory.newThread(r);
|
||||
if(r instanceof Thread) {
|
||||
t.setName(((Thread) r).getName());
|
||||
}
|
||||
return t;
|
||||
};
|
||||
//Thread pool will discard oldest task when queue reaches 333 tasks
|
||||
private static final ThreadPoolExecutor threadPool = new ThreadPoolExecutor(
|
||||
config.threadPoolSize, config.threadPoolSize, 1L, TimeUnit.MINUTES,
|
||||
new LinkedBlockingQueue<>(333), customFactory, new ThreadPoolExecutor.DiscardOldestPolicy()
|
||||
);
|
||||
|
||||
//For User Skin
|
||||
public static Map<Type, MinecraftProfileTexture> loadProfile(GameProfile gameProfile){
|
||||
|
||||
@@ -27,8 +27,8 @@ public class Config {
|
||||
public boolean forceIgnoreHttpsCertificate = false;
|
||||
public boolean forceLoadAllTextures=false;
|
||||
public boolean enableCape = true;
|
||||
public int threadPoolSize = 1;
|
||||
public int retryTime = 3;
|
||||
public int threadPoolSize = 3;
|
||||
public int retryTime = 1;
|
||||
|
||||
//Cache
|
||||
public int cacheExpiry=30;
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ProfileCache {
|
||||
public void updateCache(String username,UserProfile profile,boolean saveLocalProfile){
|
||||
CachedProfile cp=getCachedProfile(username);
|
||||
cp.profile=profile;
|
||||
cp.expiryTime=TimeUtil.getUnixTimestampRandomDelay(CustomSkinLoader.config.cacheExpiry);
|
||||
cp.expiryTime=TimeUtil.getUnixTimestamp(CustomSkinLoader.config.cacheExpiry);
|
||||
if(!saveLocalProfile)
|
||||
return;
|
||||
saveLocalProfile(username,profile);
|
||||
|
||||
Reference in new issue
Block a user