http://blog.csdn.net/sd4000784/article/details/7745947spring
1 <task:annotation-driven scheduler="myScheduler" mode="proxy"/> 2 <task:scheduler id="myScheduler" pool-size="20"/>
@Value("${url.user.all.staff}") private String userInfoUrl; private static final String CHARSET = "utf-8"; //@Scheduled(cron = "30 32 23 ? * THU") // @Scheduled(cron = "0/30 * * * * ? ") // @Scheduled(cron = "0 */1 * * * ?")//每隔 一分鐘執行 // @Scheduled(cron = "0 15 9 ? * *")///天天上午9:15觸發 // @Scheduled(cron = "0 15 10 15 * ?")///每個月15日上午10:15觸發 @Override public void updateUserOrgInfo() { LOGGER.info("UpdateUserOrgInfoJob:updateUserOrgInfo"); final String url = userInfoUrl; final HttpClientUtil httpClientUtil = new HttpClientUtil(); final String resultStr = httpClientUtil.doGet(url, CHARSET); List<Map<String, Object>> resultList=null; DataBody dataBody = null; List<AppAccount> result=null; try { dataBody = DecryptUtil.decodeJson(resultStr); final String content = dataBody.getContent();//加密數據 String password = dataBody.getPassword();//密碼 final String attendanceData = DecryptUtil.decodeData(content, password); resultList = JSON.parseObject(attendanceData, new TypeReference<List<Map<String, Object>>>(){}); result = ObjectUtils.mapsToObjects(resultList, AppAccount.class); } catch (Exception e) { e.printStackTrace(); } //遍歷全部用戶列表 for (AppAccount appAccount : result) { AppAccountValueObject valueObject = accountRepository.userAuthenticate(appAccount.getJobNumber()); if (!this.beanValidator(appAccount).getHasError().booleanValue()) { if (valueObject != null) { valueObject.setOrgId(appAccount.getOrgId()); valueObject.setDepartmentId(appAccount.getDepartmentId()); valueObject.setPassword(appAccount.getPassword()); accountRepository.updateUserOrgInfo(valueObject); LOGGER.info("UpdateUserOrgInfoJob:getJobNumber"); } else { accountRepository.insertAppUser(appAccount); LOGGER.info("UpdateUserOrgInfoJob:insertAppUser"); } } } }
其中每一個元素能夠是一個值(如6),一個連續區間(9-12),一個間隔時間(8-18/4)(/表示每隔4小時),一個列表(1,3,5),通配符。因爲"月份中的日期"和"星期中的日期"這兩個元素互斥的,必需要對 其中一個設置?.app