mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-27 20:45:27 +01:00
Merge branch 'development'
This commit is contained in:
commit
480919ca02
@ -4,7 +4,7 @@ stages:
|
||||
variables:
|
||||
name: "SongodaCore"
|
||||
path: "/builds/$CI_PROJECT_PATH"
|
||||
version: "2.3.21"
|
||||
version: "2.3.22"
|
||||
|
||||
build:
|
||||
stage: build
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user