From 72f84737e2ffee28590d35b1b3be2b656afd4fc7 Mon Sep 17 00:00:00 2001 From: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> Date: Tue, 14 Apr 2020 02:48:53 +0200 Subject: Made use of Thread.wait() + shortened "causeMachineUpdate" method Signed-off-by: bartimaeusnek <33183715+bartimaeusnek@users.noreply.github.com> --- .../api/threads/GT_Runnable_MachineBlockUpdate.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/threads') diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java index 3bac8866c3..cefbb0bc8d 100644 --- a/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java +++ b/src/main/java/gregtech/api/threads/GT_Runnable_MachineBlockUpdate.java @@ -68,6 +68,10 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable { GT_Runnable_MachineBlockUpdate.setmWorld(aWorld); GT_Runnable_MachineBlockUpdate.resetVisited(); GT_Runnable_MachineBlockUpdate.setAllowedToRun(true); + synchronized (GT_Runnable_MachineBlockUpdate.INSTANCETHREAD) { + if (GT_Runnable_MachineBlockUpdate.INSTANCETHREAD.getState() == Thread.State.WAITING) + GT_Runnable_MachineBlockUpdate.INSTANCETHREAD.notify(); + } } /** @@ -161,8 +165,17 @@ public class GT_Runnable_MachineBlockUpdate implements Runnable { //DO NOT USE OPTIONALS HERE! synchronized (toUpdate) { Coordinates coordinates = toUpdate.poll(); - if (coordinates != null) + if (coordinates != null) { coordinates.update(); + } else { + synchronized(INSTANCETHREAD) { + try { + INSTANCETHREAD.wait(); + } catch (InterruptedException ignored) { + return; + } + } + } } } } -- cgit