public class Reminder extends TimerTask
{
/** 创建日志类,用于打印日志信息 */
private static Logger logger = Logger.getLogger(Reminder.class);
/**
* 系统统计的业务bean
*/
private SystemPerformance systemCountTalkBean = null;
/**
* UNIX操作系统类型
*/
private final int linuxOSType = 3;
/**
* 操作系统类型
*/
private int osType = SystemUtil.getOSType();
/**
* 系统性能类,用于统计系统性能信息
*/
private MonitorService service = new MonitorServiceImpl();
/**
* 统计结果格式
*/
private DecimalFormat df = new DecimalFormat("#0.00");
/**
* 执行线程,统计系统性能信息
*/
@Override
public void run()
{
logger.recordEnterMethodLog();
if (null == systemCountTalkBean)
{
// 根据sysCountTalk从spring中获取系统性能对象
systemCountTalkBean = (SystemPerformance) ContextRegistry.getContextHolder().getBean("systemPerformance");
}
// 判断当前操作系统的类型
if (linuxOSType == osType)
{
// 格式化数据
SystemPerformance systemCountTalk = null;
try
{
systemCountTalk = service.getSystemPerformance();
}
catch (Exception e)
{
logger.recordErrorsLog(e.getMessage());
return;
}
// 累加CPU的适时使用率(统计5分钟内获取到得CPU利用率)
systemCountTalkBean.setCpuUseRatio(systemCountTalkBean.getCpuUseRatio() + systemCountTalk.getCpuUseRatio());
// 累加物理内存的适时使用率
systemCountTalkBean.setMemoUseRatio(Double.valueOf(
df.format(systemCountTalkBean.getMemoUseRatio()
+ systemCountTalk.getMemoUseRatio())));
// 累加交换分区实时使用率
systemCountTalkBean.setSwfSubregionUseRatio(Double.valueOf(
df.format(systemCountTalkBean.getSwfSubregionUseRatio()
+ systemCountTalk.getSwfSubregionUseRatio())));
// 每10秒执行一次时,使计数器自增
systemCountTalkBean.getCountNum().increase();
}
else
{
logger.recordDebugLog("osType is not UNIX!");
}
logger.recordExitMethodLog();
}
}
{
/** 创建日志类,用于打印日志信息 */
private static Logger logger = Logger.getLogger(Reminder.class);
/**
* 系统统计的业务bean
*/
private SystemPerformance systemCountTalkBean = null;
/**
* UNIX操作系统类型
*/
private final int linuxOSType = 3;
/**
* 操作系统类型
*/
private int osType = SystemUtil.getOSType();
/**
* 系统性能类,用于统计系统性能信息
*/
private MonitorService service = new MonitorServiceImpl();
/**
* 统计结果格式
*/
private DecimalFormat df = new DecimalFormat("#0.00");
/**
* 执行线程,统计系统性能信息
*/
@Override
public void run()
{
logger.recordEnterMethodLog();
if (null == systemCountTalkBean)
{
// 根据sysCountTalk从spring中获取系统性能对象
systemCountTalkBean = (SystemPerformance) ContextRegistry.getContextHolder().getBean("systemPerformance");
}
// 判断当前操作系统的类型
if (linuxOSType == osType)
{
// 格式化数据
SystemPerformance systemCountTalk = null;
try
{
systemCountTalk = service.getSystemPerformance();
}
catch (Exception e)
{
logger.recordErrorsLog(e.getMessage());
return;
}
// 累加CPU的适时使用率(统计5分钟内获取到得CPU利用率)
systemCountTalkBean.setCpuUseRatio(systemCountTalkBean.getCpuUseRatio() + systemCountTalk.getCpuUseRatio());
// 累加物理内存的适时使用率
systemCountTalkBean.setMemoUseRatio(Double.valueOf(
df.format(systemCountTalkBean.getMemoUseRatio()
+ systemCountTalk.getMemoUseRatio())));
// 累加交换分区实时使用率
systemCountTalkBean.setSwfSubregionUseRatio(Double.valueOf(
df.format(systemCountTalkBean.getSwfSubregionUseRatio()
+ systemCountTalk.getSwfSubregionUseRatio())));
// 每10秒执行一次时,使计数器自增
systemCountTalkBean.getCountNum().increase();
}
else
{
logger.recordDebugLog("osType is not UNIX!");
}
logger.recordExitMethodLog();
}
}