Use crontab in Linux to implement scheduled tasks for distributed projects.
@ Controller @ RequestMapping ("/task/topic") public class TopicQuartzController {protected Logger logger = LoggerFactory. getLogger (TopicQuartzController. class); @ Autowiredprivate LiveTopicService liveTopicService; @ RequestMapping ("execute") @ ResponseBodypublic CommonResult execute (HttpServletRequest request, HttpServletResponse response, String type) {long t1 = System. currentTimeMillis (); logger. error ("topic set The timer execution starts "+ type); CommonResult result = new CommonResult (); if (QlchatUtil. isEmpty (type) {result. setMsg ("parameter is blank"); result. setSuccess (false); return result;} try {switch (type) {case "autoEndTopic": this. autoEndTopic (); break; case "oneWeek": this. endTopicOneWeek (); break; default: break;} result. setSuccess (true); result. setMsg ("execution completed" + type);} catch (Exception e) {logger. error ("topic timer execution exception" + type, e); result. setMsg ("Topic timer execution exception" + type); result. setSuccess (false);} long t2 = System. currentTimeMillis (); logger. error ("topic timer execution ended" + type + ", time consumed =" + (t2-t1) + "ms"); return result;} private void autoEndTopic () {String SQL = "SELECT id _ topicId FROM skg_live_topic lt WHERE lt. 'status _ '= 'beginning' AND lt. end_time _ is not null and lt. 'End _ time _ '<NOW () "; JdbcTemplate jdbcTemplate = SpringHelper. getBean (JdbcTemplate. class ); List <Map <String, Object> resultMap = jdbcTemplate. queryForList (SQL); for (Map <String, Object> map: resultMap) {String topicId = String. valueOf (map. get ("topicId"); try {LiveTopicPo liveTopicPo = liveTopicService. loadCache (topicId); liveTopicService. endTopic (liveTopicPo, liveTopicPo. getCreateBy ();} catch (Exception e) {logger. error ("autoEndTopic exception" + topicId, e) ;}}/ *** no end time before the end of the topic, only one week */priva Te void endTopicOneWeek () {String SQL = "SELECT id _ topicId FROM skg_live_topic lt WHERE lt. 'status _ '= 'beginning' AND lt. end_time _ is null and lt. start_time _ <= (NOW ()-interval 48 hour) "; JdbcTemplate jdbcTemplate = SpringHelper. getBean (JdbcTemplate. class); List <Map <String, Object> resultMap = jdbcTemplate. queryForList (SQL); for (Map <String, Object> map: resultMap) {String topicId = String. value Of (map. get ("topicId"); try {LiveTopicPo liveTopicPo = liveTopicService. loadCache (topicId); liveTopicService. endTopic (liveTopicPo, liveTopicPo. getCreateBy ();} catch (Exception e) {logger. error ("autoEndTopic exception" + topicId, e);}}creates A contab.txt */30 *** curl 'HTTP: // 10.47.161.40: 8181/task/topic/execute. do? Type = oneWeek '*/30 ***** curl 'HTTP: // 10.47.161.40: 8181/task/topic/execute. do? Type = autoEndTopic '. In this way, you can call the method to execute the scheduled task of the Distributed Project. The task is executed every 30 minutes.