Skip to content

Commit ee0df73

Browse files
committed
Fix CPU usage detection - use com.sun.management.OperatingSystemMXBean with proper casting
1 parent 2a07653 commit ee0df73

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

core/src/main/java/lucee/commons/io/SystemUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
import org.osgi.framework.BundleException;
6464
import org.osgi.framework.BundleReference;
6565

66-
import java.lang.management.OperatingSystemMXBean;
66+
import com.sun.management.OperatingSystemMXBean;
6767

6868
import jakarta.servlet.ServletContext;
6969
import lucee.commons.collection.AccessOrderLimitedSizeMap;
@@ -1146,7 +1146,7 @@ public static long getTotalBytes() throws ApplicationException {
11461146

11471147
public static double getCpuUsage(long time) throws ApplicationException {
11481148
if (time < 1) throw new ApplicationException("time has to be bigger than 0");
1149-
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
1149+
OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
11501150
double cpuBefore = osBean.getProcessCpuTime();
11511151
long timeBeforeNano = System.nanoTime();
11521152
sleep(time);
@@ -1158,7 +1158,7 @@ public static double getCpuUsage(long time) throws ApplicationException {
11581158
}
11591159

11601160
public static float getCpuPercentage() {
1161-
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
1161+
OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
11621162
int max = 50;
11631163
float res = 0;
11641164
while (true) {
@@ -1177,7 +1177,7 @@ public static float getCpuPercentage() {
11771177
}
11781178

11791179
private synchronized static PhysicalMemory physical() throws ApplicationException {
1180-
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
1180+
OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
11811181
try {
11821182
long totalPhysicalMemory = osBean.getTotalPhysicalMemorySize();
11831183
long freePhysicalMemory = osBean.getFreePhysicalMemorySize();

0 commit comments

Comments
 (0)