Merge branch 'development'

This commit is contained in:
Brianna 2020-04-15 12:41:34 -04:00
commit 480919ca02
3 changed files with 36 additions and 1 deletions

View File

@ -4,7 +4,7 @@ stages:
variables:
name: "SongodaCore"
path: "/builds/$CI_PROJECT_PATH"
version: "2.3.21"
version: "2.3.22"
build:
stage: build

View File

@ -17,6 +17,8 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import java.util.logging.Level;
import com.songoda.core.database.DataManagerAbstract;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -402,6 +404,8 @@ public class SongodaCore {
if (pi != null) {
registeredPlugins.remove(pi);
}
// Terminate all active threads
DataManagerAbstract.terminateAllThreads();
if (event.getPlugin() == piggybackedPlugin) {
// uh-oh! Abandon ship!!
Bukkit.getServicesManager().unregisterAll(piggybackedPlugin);

View File

@ -11,6 +11,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
public class DataManagerAbstract {
@ -88,4 +89,34 @@ public class DataManagerAbstract {
threads.computeIfAbsent(threadKey.toUpperCase(),
t -> Executors.newSingleThreadScheduledExecutor()).execute(runnable);
}
/**
* Terminate thread once all tasks have been completed.
*
* @param threadKey the thread key to terminate.
*/
public static void terminateThread(String threadKey) {
ScheduledExecutorService service = threads.get(threadKey);
if (service != null) {
threads.remove(threadKey);
try {
service.awaitTermination(0, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
/**
* Terminate all active threads.
*/
public static void terminateAllThreads() {
for (ScheduledExecutorService service : threads.values()) {
try {
service.awaitTermination(0, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}