automatic task class:
@PersistJobDataAfterExecution @DisallowConcurrentExecution public class ReCodeBack implements Job { private static final Logger LOGGER = LoggerFactory.getLogger(ReCodeBack.class); @Autowired ReCodeBackTag reCodeBackTag; @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { reCodeBackTag.backupsReCode(); } }
Automatic task annotation:
@PersistJobDataAfterExecution
@DisallowConcurrentExecution
task requirements are transactions that need to be added
use spring annotation @ transactional annotation
/** * Adding (deleting) table data * @param object * @param modular * @return */ @Transactional(rollbackFor = Exception.class) public int tableOperation (Object object,String modular){ int count = 0; try{ ....... }catch (Exception e) { LOGGER.info("[Add (delete) table data] ERROR : {}", e.getMessage()); //transaction rollback TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //Task is abnormally interrupted and immediately re-run JobExecutionException e2 = new JobExecutionException(e); e2.setRefireImmediately(true); throw e2; }finally { return count; } }
Note: when the author uses @transactional annotation in the automatic task class, the program will report an error (too lazy… The reason is not clear, and it will be supplemented later). Therefore, the author is divided into two classes to write, one-timing call class and one business class, as shown in the above code
Similar Posts:
- How to Solve stale element reference: element is not attached to the page document
- Spring: How to Solve Global exception @restcontrolleradvice
- [Solved] Django error: AttributeError: ‘QuerySet’ object has no attribute ‘id’
- Python3 urlopen() TypeError: can’t convert ‘bytes’ object to str im…
- Accessdeniedhandler configured in spring security does not take effect
- Thinkphp6 Error: constraint violation: 1052 Column ‘id’ in where clause is ambiguous
- [Solved] java.lang.Long cannot be cast to java.lang.Integer
- Springboot starts with @ scheduled and reports an error: no qualifying bean
- [LeetCode] 291. Word Pattern II
- Tomcat set x-frame-option