下面这个Action:
public void dataUpdateJob(){
try {
//获取监控数据更新时间
SysParam sysParam = sysParamService.getSysParamByParamCode(Constants.DATA_UPDATE_TIME);
if(sysParam!=null&&StringUtils.isNotBlank(sysParam.getParamValue())){
//获取新定时器时间,单位为毫秒,不用转换
Long newRepeatInterval = new Long(Long.parseLong(sysParam.getParamValue().trim()));
scheduleConfigManager.reScheduleJob(newRepeatInterval, "dataUpdateTimeTrigger");
//刷新数据,判断是否报警,如果报警,则报警
deviceMeasureService.updateDataToDisplay();
System.out.println("dataUpdateJob Target methed execute at "
+ Calendar.getInstance().getTime().toLocaleString());
}
} catch (ParseException e) {
e.printStackTrace();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
调用:实现类
public void updateDataToDisplay() {
try {
//获取报警设置为“报警”的监测量设置
List<AlarmParamSet> alarmParamSetList = alarmParamSetService.getHasAlarmParamSetList();
if(alarmParamSetList!=null&&alarmParamSetList.size()>0){
for(AlarmParamSet aps : alarmParamSetList){
if(aps!=null&&StringUtils.isNotBlank(aps.getMeasureId())){
//获取最新监测量值,并比较,是否需要报警
DeviceMeasure dm = this.getDevMeaByMeaId(aps.getMeasureId());
if(dm!=null&&StringUtils.isNotBlank(dm.getMeasureData())){
String alarmLevel = "";
if(StringUtils.isNotBlank(aps.getAlarmSupMin())){
//超低
alarmLevel = "1";
}else if(StringUtils.isNotBlank(aps.getAlarmMin())){
//低
alarmLevel = "2";
}else if(StringUtils.isNotBlank(aps.getAlarmMax())){
//高
alarmLevel = "3";
}else if(StringUtils.isNotBlank(aps.getAlarmSupMax())){
//超高
alarmLevel = "4";
}
if(StringUtils.isNotBlank(alarmLevel)){
//报警等级不为空时,有报警事件发生
AlarmEventPending alarmEventPending = alarmEventPendingService.getAlarmEventPendingById(dm.getDeviceMeasureId());
if(alarmEventPending==null){
alarmEventPending = new AlarmEventPending();
}
//AlarmEventPending alarmEventPending = new AlarmEventPending();
alarmEventPending.setDeviceId(dm.getDeviceId());
alarmEventPending.setMeasureId(dm.getDeviceMeasureId());
alarmEventPending.setMeasureCode(dm.getMeasureCode());
alarmEventPending.setMeasureName(dm.getMeasureName());
alarmEventPending.setAlarmData(dm.getMeasureData());
alarmEventPending.setAlarmTime(TimeHelper.getCurrentTime());
AlarmParamSet alarmParamSet = alarmParamSetService.getAlarmParamSetByMeasureId(dm.getDeviceMeasureId());
alarmEventPending.setAlarmLevel(alarmParamSet.getAlarmLevel());
alarmEventPending.setAlarmType(Constants.ALARM_SYS);
//AlarmGroup alarmGroup = alarmGroupService.getAlmGroByAlmGroId(alarmParamSet.getAlarmGroupCode());
//AlarmGroupDetail alarmGroupDetail = alarmGroupDetailService.getAlGroupDetByAlGroupDetId(alarmGroup.getAlmgrGroupId());
alarmEventPending.setState(Constants.DELETED_FOR_SYS);
alarmEventPendingService.saveAlarmEventPending(alarmEventPending);
dm.setMeasureAlarm(Constants.IS_ALARM);
updateDeviceMeasure(dm);
}
}

}
}
}
} catch (BizException e) {
e.printStackTrace();
}
}保存方法alarmEventPendingService.saveAlarmEventPending(alarmEventPending);时再次调用
public void saveAlarmEventPending(AlarmEventPending alarmEventPending) {
if(alarmEventPending!=null){
if(StringUtils.isNotBlank(alarmEventPending.getAlarmEventId())){
alarmEventPendingDao.update(alarmEventPending);
}else{
alarmEventPending.setAlarmEventId(null);
alarmEventPendingDao.save(alarmEventPending);
}
}
}实现类时报错,以下是错误提示:
11:48:54 ERROR [org.quartz.core.JobRunShell:225] - <Job DEFAULT.dataUpdateJobDetail threw an unhandled Exception: >
org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'dataUpdateJob' on target class [class com.gsww.emonitor.quartz.ScheduleInfoAction] failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:269) [spring-context-support-2.5.6.jar:2.5.6]
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86) [spring-context-support-2.5.6.jar:2.5.6]
at org.quartz.core.JobRunShell.run(JobRunShell.java:216) [quartz-1.8.3.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [quartz-1.8.3.jar:na]
Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) [spring-orm-2.5.6.jar:2.5.6]
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
at com.gsww.emonitor.commons.dao.HibernateGenericDao.save(HibernateGenericDao.java:77) [HibernateGenericDao.class:na]
at com.gsww.emonitor.biz.service.impl.AlarmEventPendingServiceImpl.saveAlarmEventPending(AlarmEventPendingServiceImpl.java:55) [AlarmEventPendingServiceImpl.class:na]
at com.gsww.emonitor.biz.service.impl.DeviceMeasureServiceImpl.updateDataToDisplay(DeviceMeasureServiceImpl.java:181) [DeviceMeasureServiceImpl.class:na]
at com.gsww.emonitor.quartz.ScheduleInfoAction.dataUpdateJob(ScheduleInfoAction.java:34) [ScheduleInfoAction.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_10-rc2]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [na:1.6.0_10-rc2]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [na:1.6.0_10-rc2]
at java.lang.reflect.Method.invoke(Unknown Source) [na:1.6.0_10-rc2]
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276) [spring-core-2.5.6.jar:2.5.6]
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260) [spring-context-support-2.5.6.jar:2.5.6]
... 3 common frames omitted
11:48:54 ERROR [org.quartz.core.ErrorLogger:2333] - <Job (DEFAULT.dataUpdateJobDetail threw an exception.>
org.quartz.SchedulerException: Job threw an unhandled exception.
at org.quartz.core.JobRunShell.run(JobRunShell.java:227) [quartz-1.8.3.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:549) [quartz-1.8.3.jar:na]
Caused by: org.springframework.scheduling.quartz.JobMethodInvocationFailedException: Invocation of method 'dataUpdateJob' on target class [class com.gsww.emonitor.quartz.ScheduleInfoAction] failed; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:269) [spring-context-support-2.5.6.jar:2.5.6]
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86) [spring-context-support-2.5.6.jar:2.5.6]
at org.quartz.core.JobRunShell.run(JobRunShell.java:216) [quartz-1.8.3.jar:na]
... 1 common frames omitted
Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
at org.springframework.orm.hibernate3.SpringSessionContext.currentSession(SpringSessionContext.java:63) [spring-orm-2.5.6.jar:2.5.6]
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:622) [hibernate-core-3.3.2.GA.jar:3.3.2.GA]
at com.gsww.emonitor.commons.dao.HibernateGenericDao.save(HibernateGenericDao.java:77) [HibernateGenericDao.class:na]
at com.gsww.emonitor.biz.service.impl.AlarmEventPendingServiceImpl.saveAlarmEventPending(AlarmEventPendingServiceImpl.java:55) [AlarmEventPendingServiceImpl.class:na]
at com.gsww.emonitor.biz.service.impl.DeviceMeasureServiceImpl.updateDataToDisplay(DeviceMeasureServiceImpl.java:181) [DeviceMeasureServiceImpl.class:na]
at com.gsww.emonitor.quartz.ScheduleInfoAction.dataUpdateJob(ScheduleInfoAction.java:34) [ScheduleInfoAction.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [na:1.6.0_10-rc2]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) [na:1.6.0_10-rc2]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) [na:1.6.0_10-rc2]
at java.lang.reflect.Method.invoke(Unknown Source) [na:1.6.0_10-rc2]
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:276) [spring-core-2.5.6.jar:2.5.6]
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean$MethodInvokingJob.executeInternal(MethodInvokingJobDetailFactoryBean.java:260) [spring-context-support-2.5.6.jar:2.5.6]
... 3 common frames omitted急需高人解决。