mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +03:00
[FEATURE] Переход на ThreadPool.
This commit is contained in:
parent
7c5c4faa75
commit
90b91a9635
3 changed files with 4 additions and 40 deletions
|
@ -71,8 +71,6 @@ public void start(String... args) throws Throwable {
|
||||||
throw new IllegalStateException("Launcher has been already started");
|
throw new IllegalStateException("Launcher has been already started");
|
||||||
Launcher.modulesManager.initModules();
|
Launcher.modulesManager.initModules();
|
||||||
runtimeProvider.preLoad();
|
runtimeProvider.preLoad();
|
||||||
FunctionalBridge.worker = new RequestWorker();
|
|
||||||
CommonHelper.newThread("Task Worker", true, FunctionalBridge.worker).start();
|
|
||||||
FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID);
|
FunctionalBridge.getHWID = CommonHelper.newThread("GetHWID Thread", true, FunctionalBridge::getHWID);
|
||||||
FunctionalBridge.getHWID.start();
|
FunctionalBridge.getHWID.start();
|
||||||
LogHelper.debug("Dir: %s", DirBridge.dir);
|
LogHelper.debug("Dir: %s", DirBridge.dir);
|
||||||
|
|
|
@ -1,30 +0,0 @@
|
||||||
package ru.gravit.launcher;
|
|
||||||
|
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
import java.util.concurrent.BlockingQueue;
|
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
|
||||||
|
|
||||||
public class RequestWorker implements Runnable {
|
|
||||||
public RequestWorker() {
|
|
||||||
queue = new LinkedBlockingQueue<>(64);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BlockingQueue<Runnable> queue;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
LogHelper.debug("FX Task Thread start");
|
|
||||||
while (!Thread.interrupted()) {
|
|
||||||
try {
|
|
||||||
Runnable task;
|
|
||||||
task = queue.take();
|
|
||||||
task.run();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LogHelper.error(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LogHelper.debug("FX Task Thread done");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,7 +3,6 @@
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import ru.gravit.launcher.HWID;
|
import ru.gravit.launcher.HWID;
|
||||||
import ru.gravit.launcher.LauncherAPI;
|
import ru.gravit.launcher.LauncherAPI;
|
||||||
import ru.gravit.launcher.RequestWorker;
|
|
||||||
import ru.gravit.launcher.hasher.FileNameMatcher;
|
import ru.gravit.launcher.hasher.FileNameMatcher;
|
||||||
import ru.gravit.launcher.hasher.HashedDir;
|
import ru.gravit.launcher.hasher.HashedDir;
|
||||||
import ru.gravit.launcher.hwid.OshiHWIDProvider;
|
import ru.gravit.launcher.hwid.OshiHWIDProvider;
|
||||||
|
@ -13,17 +12,18 @@
|
||||||
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
|
import ru.gravit.launcher.request.update.LegacyLauncherRequest;
|
||||||
import ru.gravit.launcher.request.websockets.RequestInterface;
|
import ru.gravit.launcher.request.websockets.RequestInterface;
|
||||||
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
import ru.gravit.launcher.serialize.signed.SignedObjectHolder;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
public class FunctionalBridge {
|
public class FunctionalBridge {
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static LauncherSettings settings;
|
public static LauncherSettings settings;
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static RequestWorker worker;
|
public static ExecutorService worker = Executors.newWorkStealingPool();
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider();
|
public static OshiHWIDProvider hwidProvider = new OshiHWIDProvider();
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
@ -64,11 +64,7 @@ public static void makeJsonRequest(RequestInterface request, Runnable callback)
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public static void startTask(@SuppressWarnings("rawtypes") Task task) {
|
public static void startTask(@SuppressWarnings("rawtypes") Task task) {
|
||||||
try {
|
worker.execute(task);
|
||||||
worker.queue.put(task);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
LogHelper.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
|
|
Loading…
Reference in a new issue