查看: 1893|回复: 0

[Java语言] 线程池片段写法笔记学习

发表于 2018-2-3 08:00:05
  1. private ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5);
  2. public void buildSecurityFillTask() {
  3. List<EtfRedemptionDetailPojo> redemps = etfRedemptionDetailService.selectCmbNo();
  4. if(!CollectionUtils.isEmpty(redemps)){
  5. for(final EtfRedemptionDetailPojo etf : redemps){
  6. fixedThreadPool.submit(new Runnable() {
  7. @Override
  8. public void run() {
  9. String cmbNo = etf.getCmbNo();
  10. String marketNo = etf.getMarketNo();
  11. String redempType = etf.getRedemptionType();
  12. Thread.currentThread().setName("security-fill-" + Thread.currentThread().getName());
  13. try{
  14. buildSecurityFill(cmbNo, marketNo, redempType);
  15. logService.log(getClass(), "StandingBookBuildServiceImpl.buildSecurityFillTask",
  16. "执行待补券成功,组合编号:" + cmbNo + ",市场代码:" + marketNo + ", 申赎标识:" + redempType, LogType.INFO, null);
  17. }catch(Exception e){
  18. logService.error(getClass(), "待补券失败", "StandingBookBuildServiceImpl.buildSecurityFillTask",
  19. "执行待补券失败,组合编号:" + cmbNo + ",市场代码:" + marketNo + ", 申赎标识:" + redempType);
  20. logger.error("执行待补券失败,组合编号:" + cmbNo + ",市场代码:" + marketNo + ", 申赎标识:" + redempType, e);
  21. }
  22. }
  23. });
  24. }
  25. }else {
  26. logService.log(getClass(), "StandingBookBuildServiceImpl.buildSecurityFillTask",
  27. "未取到需要补券的数据", LogType.WARN, null);
  28. }
  29. }
复制代码


回复

使用道具 举报