懒羊羊
2024-01-31 e57a8990ae56f657a59c435a0613c5f7a8728003
提交 | 用户 | 时间
e57a89 1 package com.jcdm.framework.web.domain.server;
2
3 import java.lang.management.ManagementFactory;
4 import com.jcdm.common.utils.Arith;
5 import com.jcdm.common.utils.DateUtils;
6
7 /**
8  * JVM相关信息
9  * 
10  * @author jc
11  */
12 public class Jvm
13 {
14     /**
15      * 当前JVM占用的内存总数(M)
16      */
17     private double total;
18
19     /**
20      * JVM最大可用内存总数(M)
21      */
22     private double max;
23
24     /**
25      * JVM空闲内存(M)
26      */
27     private double free;
28
29     /**
30      * JDK版本
31      */
32     private String version;
33
34     /**
35      * JDK路径
36      */
37     private String home;
38
39     public double getTotal()
40     {
41         return Arith.div(total, (1024 * 1024), 2);
42     }
43
44     public void setTotal(double total)
45     {
46         this.total = total;
47     }
48
49     public double getMax()
50     {
51         return Arith.div(max, (1024 * 1024), 2);
52     }
53
54     public void setMax(double max)
55     {
56         this.max = max;
57     }
58
59     public double getFree()
60     {
61         return Arith.div(free, (1024 * 1024), 2);
62     }
63
64     public void setFree(double free)
65     {
66         this.free = free;
67     }
68
69     public double getUsed()
70     {
71         return Arith.div(total - free, (1024 * 1024), 2);
72     }
73
74     public double getUsage()
75     {
76         return Arith.mul(Arith.div(total - free, total, 4), 100);
77     }
78
79     /**
80      * 获取JDK名称
81      */
82     public String getName()
83     {
84         return ManagementFactory.getRuntimeMXBean().getVmName();
85     }
86
87     public String getVersion()
88     {
89         return version;
90     }
91
92     public void setVersion(String version)
93     {
94         this.version = version;
95     }
96
97     public String getHome()
98     {
99         return home;
100     }
101
102     public void setHome(String home)
103     {
104         this.home = home;
105     }
106
107     /**
108      * JDK启动时间
109      */
110     public String getStartTime()
111     {
112         return DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getServerStartDate());
113     }
114
115     /**
116      * JDK运行时间
117      */
118     public String getRunTime()
119     {
120         return DateUtils.timeDistance(DateUtils.getNowDate(), DateUtils.getServerStartDate());
121     }
122
123     /**
124      * 运行参数
125      */
126     public String getInputArgs()
127     {
128         return ManagementFactory.getRuntimeMXBean().getInputArguments().toString();
129     }
130 }