diff --git a/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/model/SystemMetrics.java b/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/model/SystemMetrics.java index e1c384a4..1d5945ec 100644 --- a/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/model/SystemMetrics.java +++ b/powerjob-common/src/main/java/com/github/kfcfans/powerjob/common/model/SystemMetrics.java @@ -34,7 +34,8 @@ public class SystemMetrics implements OmsSerializable, Comparable @Override public int compareTo(SystemMetrics that) { - return this.calculateScore() - that.calculateScore(); + // 降序排列 + return that.calculateScore() - this.calculateScore(); } /** diff --git a/powerjob-worker/src/test/java/com/github/kfcfans/powerjob/function/MonitorTest.java b/powerjob-worker/src/test/java/com/github/kfcfans/powerjob/function/MonitorTest.java index a4aa69f0..3cb53acb 100644 --- a/powerjob-worker/src/test/java/com/github/kfcfans/powerjob/function/MonitorTest.java +++ b/powerjob-worker/src/test/java/com/github/kfcfans/powerjob/function/MonitorTest.java @@ -4,11 +4,14 @@ import com.github.kfcfans.powerjob.common.model.SystemMetrics; import com.github.kfcfans.powerjob.common.utils.JsonUtils; import com.github.kfcfans.powerjob.worker.common.utils.SystemInfoUtils; import com.google.common.base.Stopwatch; +import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.OperatingSystemMXBean; +import java.util.Collections; +import java.util.List; /** * 测试监控指标 @@ -58,4 +61,18 @@ public class MonitorTest { SystemMetrics systemMetrics = SystemInfoUtils.getSystemMetrics(); System.out.println(JsonUtils.toJSONString(systemMetrics)); } + + @Test + public void testSortMetrics() { + SystemMetrics high = new SystemMetrics(); + high.setScore(100); + SystemMetrics low = new SystemMetrics(); + low.setScore(1); + List list = Lists.newArrayList(high, low); + list.sort((o1, o2) -> o2.calculateScore() - o1.calculateScore()); + System.out.println(list); + + Collections.sort(list); + System.out.println(list); + } }