SteamWar/BauSystem
Archiviert
13
0

Add RamUsage to be safe

Dieser Commit ist enthalten in:
yoyosource 2021-04-02 19:05:02 +02:00
Ursprung 7653bd22f9
Commit efaf18a4f8
2 geänderte Dateien mit 37 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -170,9 +170,7 @@ public class BauSystem extends JavaPlugin implements Listener {
} }
count++; count++;
try { try {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize(); if (RamUsage.getUsage() > 0.8) {
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
if ((memorySize - freeMemory) / (double) memorySize > 0.8) {
Bukkit.shutdown(); Bukkit.shutdown();
} }
} catch (Throwable throwable) { } catch (Throwable throwable) {

Datei anzeigen

@ -0,0 +1,36 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.bausystem;
import java.lang.management.ManagementFactory;
public class RamUsage {
public static double getUsage() {
try {
long memorySize = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getTotalPhysicalMemorySize();
long freeMemory = ((com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean()).getFreePhysicalMemorySize();
return (memorySize - freeMemory) / (double) memorySize;
} catch (Throwable throwable) {
return 1D;
}
}
}