From 5c01d5fd1768a0cf16ed1f5dc8ed9f0954769f77 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sun, 11 Nov 2018 16:16:05 +0700 Subject: [PATCH] =?UTF-8?q?Thread-safe=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20RequestWorker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/gravit/launcher/client/FunctionalBridge.java | 7 ++++++- .../java/ru/gravit/launcher/client/RequestWorker.java | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java index cc9499e7..6cfd4c3a 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/FunctionalBridge.java @@ -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); + } } } diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java b/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java index 6cfbd202..6b8942c2 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/RequestWorker.java @@ -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; } } }