【发布时间】:2018-09-19 06:30:16
【问题描述】:
我编写了一个任务调度程序作业,它每 30 分钟为符合条件的患者生成账单。在这里,我很困惑我保持的传播和隔离级别是否按照标准是正确的。我应该始终使用 REQUIRES_NEW 作为传播的一部分吗?
关于以下部分的任何建议。
private void startBilling() throws Exception {
List<Integer> patientIds = null;
try {
patientIds = getPatientsForBilling();
if(null != patientIds) {
for(Integer patient : patientIds) {
updatePatientDetails(patient, "STARTED", jdbcTemplate);
makeBillForPatient(patient, jdbcTemplate);
updatePatientDetails(patient, "COMPLETED", jdbcTemplate);
}
}
} catch (Exception e) {
//LOG HERE
updatePatientDetails(patient, "TERMINATED", jdbcTemplate);
}
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
private void makeBillForPatient(Integer patient, JdbcTemplate jdbcTemplate2) {
// A bill for the patient will be generated and printed
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
private void updatePatientDetails(Integer patient,
String status, JdbcTemplate jdbcTemplate) {
// Update the patient billing status STARTED
}
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
private List<Integer> getPatientsForBilling() {
return new ArrayList<Integer>();
}
这是我实现的逻辑
- 一旦任务调度程序启动,它将获取所有符合条件的患者进行计费(即出院的患者)
- 它会将状态更新为已启动。
- 它将生成账单
- 它会将状态更新为 COMPLETED
任何想法将不胜感激。
【问题讨论】:
-
除非您使用 AspectJ 或类似的东西,否则注释私有方法几乎是无用的:据我所知,Spring 默认使用代理 AOP,它不会拦截自我调用。
标签: spring spring-transactions