From cd7b7a550df68b34bf899632b8a11d81db1e459d Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 31 Aug 2018 16:40:24 +0200 Subject: [PATCH] Might have fixed the stop delay The theory is the following: multiple BS threads were created, one for each chunk, which caused long locks. If this isn't the case, I don't know what is. #2 --- .../blockstate/thread/ThreadLink.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java index 85d66cd..324353d 100644 --- a/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java +++ b/src/main/java/de/jaschastarke/minecraft/limitedcreative/blockstate/thread/ThreadLink.java @@ -1,22 +1,21 @@ package de.jaschastarke.minecraft.limitedcreative.blockstate.thread; +import de.jaschastarke.bukkit.lib.ModuleLogger; +import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; +import de.jaschastarke.minecraft.limitedcreative.blockstate.AbstractModel.HasBlockState; +import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState; +import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid; +import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries; +import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; +import org.bukkit.Chunk; +import org.bukkit.Location; +import org.bukkit.block.Block; + import java.lang.Thread.UncaughtExceptionHandler; import java.util.LinkedList; import java.util.List; import java.util.Stack; -import org.bukkit.Chunk; -import org.bukkit.Location; -import org.bukkit.block.Block; - -import de.jaschastarke.bukkit.lib.ModuleLogger; -import de.jaschastarke.minecraft.limitedcreative.ModBlockStates; -import de.jaschastarke.minecraft.limitedcreative.blockstate.BlockState; -import de.jaschastarke.minecraft.limitedcreative.blockstate.AbstractModel.HasBlockState; -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBModel.Cuboid; -import de.jaschastarke.minecraft.limitedcreative.blockstate.DBQueries; -import de.jaschastarke.minecraft.limitedcreative.blockstate.ThreadedModel; - public class ThreadLink { private static final int BATCH_ACTION_LENGTH = 25; private static final int QUEUE_ACCESS_WARNING_DURATION = 5; // ms @@ -40,6 +39,7 @@ public class ThreadLink { * In theory we could add multiple threads, e.g. 1 write and 2 read threads. */ createThread(queries); + shutdown = true; //Don't allow the thread to run until it's started } private class DBThread extends Thread { @@ -108,6 +108,7 @@ public class ThreadLink { } public void start() { + shutdown = false; if (!thread.isAlive()) thread.start(); } @@ -213,14 +214,17 @@ public class ThreadLink { } private void restartThreadIfNeeded() { - if(thread.isAlive()) + if ((thread != null && thread.isAlive()) || shutdown) return; log.warn("Thread is dead, restarting!"); + new Exception("Thread-restarting update called").printStackTrace(); createThread(((DBThread) thread).q); start(); } private void createThread(DBQueries queries) { + if (shutdown) + return; thread = new DBThread(queries); thread.setName("LC BlockState DB-Thread"); thread.setUncaughtExceptionHandler(new UncaughtExceptionHandler() {