mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 17:11:39 +03:00
Thread-safe функции RequestWorker
This commit is contained in:
parent
f21572879e
commit
5c01d5fd17
2 changed files with 12 additions and 3 deletions
|
@ -9,6 +9,7 @@
|
||||||
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.CommonHelper;
|
import ru.gravit.utils.helper.CommonHelper;
|
||||||
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -58,6 +59,10 @@ public void makeJsonRequest(RequestInterface request, Runnable callback)
|
||||||
@LauncherAPI
|
@LauncherAPI
|
||||||
public void startTask(Task task)
|
public void startTask(Task task)
|
||||||
{
|
{
|
||||||
worker.queue.offer(task);
|
try {
|
||||||
|
worker.queue.put(task);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,13 @@ public RequestWorker()
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!Thread.interrupted())
|
while (!Thread.interrupted())
|
||||||
{
|
{
|
||||||
Task task = queue.poll();
|
try {
|
||||||
if (task != null) {
|
Task task;
|
||||||
|
task = queue.take();
|
||||||
task.run();
|
task.run();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LogHelper.error(e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue