SteamWar/BauSystem
Archiviert
13
0

Add BauSystem shutdown after 5 minutes no player or 80 percentage memory load

Dieser Commit ist enthalten in:
yoyosource 2021-04-02 18:54:46 +02:00
Ursprung 6a62dde065
Commit 0337c1eb53

Datei anzeigen

@ -46,6 +46,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.lang.management.ManagementFactory;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
@ -171,19 +172,27 @@ public class BauSystem extends JavaPlugin implements Listener {
if (autoShutdown != null) { if (autoShutdown != null) {
autoShutdown.cancel(); autoShutdown.cancel();
} }
/*autoShutdown = Bukkit.getScheduler().runTaskTimer(this, () -> { autoShutdown = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
try { int count = 0;
ProcessBuilder processBuilder = new ProcessBuilder("/bin/bash", "-c", "free");
Process process = processBuilder.start(); @Override
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); public void run() {
bufferedReader.readLine(); if (count >= 5) {
String s = bufferedReader.readLine(); Bukkit.shutdown();
} catch (IOException exception) { return;
Bukkit.shutdown(); }
count++;
try {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
if ((memorySize - freeMemory) / (double) memorySize > 0.8) {
Bukkit.shutdown();
}
} catch (Throwable throwable) {
Bukkit.shutdown();
}
} }
}, 1200, 1200);*/ }, 1200, 1200);
// (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / Runtime.getRuntime().maxMemory() > 0.8
autoShutdown = Bukkit.getScheduler().runTaskLater(this, Bukkit::shutdown, 6000);
} }
} }