mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +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.serialize.signed.SignedObjectHolder;
|
||||
import ru.gravit.utils.helper.CommonHelper;
|
||||
import ru.gravit.utils.helper.LogHelper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
@ -58,6 +59,10 @@ public void makeJsonRequest(RequestInterface request, Runnable callback)
|
|||
@LauncherAPI
|
||||
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() {
|
||||
while (!Thread.interrupted())
|
||||
{
|
||||
Task task = queue.poll();
|
||||
if (task != null) {
|
||||
try {
|
||||
Task task;
|
||||
task = queue.take();
|
||||
task.run();
|
||||
} catch (InterruptedException e) {
|
||||
LogHelper.error(e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue