java之定时任务

Posted 有猿人

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java之定时任务相关的知识,希望对你有一定的参考价值。

技术分享图片
  1 package com.financial.server.util;
  2 import java.text.SimpleDateFormat;
  3 import java.util.Date;
  4 import java.util.HashMap;
  5 import java.util.Map;
  6 import org.springframework.beans.factory.annotation.Autowired;
  7 import org.springframework.scheduling.annotation.Scheduled;
  8 import org.springframework.stereotype.Component;
  9 
 10 import com.financial.server.service.impl.GSXQ_K_LineOfDayService;
 11 import com.financial.server.service.impl.GSYJReportService;
 12 import com.financial.server.service.impl.HGYJReportService;
 13 import com.financial.server.service.impl.HYYYReportService;
 14 import com.financial.server.service.impl.JuChaoServiceImpl;
 15 import com.financial.server.service.impl.LongHuBangDetailsService;
 16 import com.financial.server.service.impl.QSCHReportService;
 17 import com.financial.server.service.impl.SHZQService;
 18 import com.financial.server.service.impl.SZZQService;
 19 import com.financial.server.service.impl.TZCLReportService;
 20 import com.financial.server.service.impl.TaoGuBaService;
 21 import com.financial.server.service.impl.XGYBReportService;
 22 import com.financial.server.thread.GSYJThread;
 23 import com.financial.server.thread.HGYJThread;
 24 import com.financial.server.thread.HYYYThread;
 25 import com.financial.server.thread.JuChaoDownloadThread;
 26 import com.financial.server.thread.KOfDayThread;
 27 import com.financial.server.thread.LongHuBangDetailsThread;
 28 import com.financial.server.thread.QSCHThread;
 29 import com.financial.server.thread.SHZQThread;
 30 import com.financial.server.thread.SZZQThread;
 31 import com.financial.server.thread.TGBThread;
 32 import com.financial.server.thread.TZCLThread;
 33 import com.financial.server.thread.XGYBThread;
 34 
 35 
 36 @Component  
 37 public class TimerTask { 
 38     @Autowired
 39     private GSXQ_K_LineOfDayService kOfDayService;
 40     
 41     
 42     @Autowired
 43     private JuChaoServiceImpl juChaoServiceImpl;
 44     
 45     @Autowired
 46     private TaoGuBaService taoGuBaService;
 47     
 48     @Autowired
 49     private GSYJReportService gsyjReportService;
 50     @Autowired
 51     private XGYBReportService xgybReportService;
 52     @Autowired
 53     private HYYYReportService hyyyReportService;
 54     /*@Autowired
 55     private GNYBReportService gnybReportService;*/
 56     @Autowired
 57     private TZCLReportService tzclReportService;
 58     @Autowired
 59     private QSCHReportService qschReportService;
 60     @Autowired
 61     private HGYJReportService hgyjReportService;
 62     
 63     @Autowired
 64     private LongHuBangDetailsService longHuBangDetailsService;
 65     
 66     @Autowired
 67     private JuChaoServiceImpl juchChaoServiceImpl;
 68     @Autowired
 69     private GSXQ_K_LineOfDayService gsxq_K_LineOfDayService;
 70     
 71     String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());//
 72     //String date = "2018-07-12";
 73     String typeFile = "F:/巨潮网/巨潮网公告类别.txt";
 74     @Scheduled(cron = "0 59 13 ? * *")//每天15:04执行一次  
 75     public void doSomethingWithCron() {  
 76         try {
 77              
 78              
 79             
 80             //插入跟帖
 81             /*Map<String, String> map = TaoGuBa.webParsehtmls("https://www.taoguba.com.cn/index?blockID=1");
 82             String JessionID = map.get("JSESSIONID").toString();
 83             String cookie = TaoGuBa.SubmitPost(JessionID); 
 84             new Thread(new TGBThread(taoGuBaService, date, date,true)).start();//淘股吧
 85 */            
 86             new Thread(new GSYJThread(gsyjReportService, date, date,true)).start();//公司研究
 87             
 88             new Thread(new XGYBThread(xgybReportService, date, date,true)).start();//新股研报
 89             
 90             new Thread(new HYYYThread(hyyyReportService, date, date,true)).start();//行业研究
 91             
 92             new Thread(new TZCLThread(tzclReportService, date, date,true)).start();//投资策略
 93             
 94             new Thread(new QSCHThread(qschReportService, date, date,true)).start();//券商晨会
 95             
 96             new Thread(new HGYJThread(hgyjReportService, date, date,true)).start();//宏观研究
 97             
 98            new Thread(new LongHuBangDetailsThread(longHuBangDetailsService, date, date,true)).start();//龙虎榜详情
 99             
100             
101             new Thread(new JuChaoThread(juchChaoServiceImpl,typeFile,date, date,true)).start();//巨潮网公告
102             
103             
104             new Thread(new KOfDayThread(gsxq_K_LineOfDayService,date,true)).start();//日k线数据
105             
106              
107             
108         } catch (Exception e) {
109             e.printStackTrace();
110         } 
111     }  
112   
113 }  
View Code

 

以上是关于java之定时任务的主要内容,如果未能解决你的问题,请参考以下文章

Java定时任务工具详解之Timer篇

Java定时任务工具详解之Timer篇

Java定时任务之Timer

死磕 java线程系列之线程池深入解析——定时任务执行流程

java定时任务之Timer和ScheduledExecutorService

java之定时任务