package com.sdwlf.job.entInfo.service;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import com.freework.base.exception.AppException;
public class EntInfoRunnable implements Runnable {
public static ApplicationContext context = null;
private String startTime;
private String endTime;
public EntInfoRunnable(String startTime, String endTime) {
this.startTime = startTime;
this.endTime = endTime;
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
@Override
public void run() {
JobEntInfoService service = (JobEntInfoService) this.getInstance("com.sdwlf.job.entInfo.service.JobEntInfoService");
try {
Thread.sleep(1000);
System.out.println(startTime+" "+endTime);
service.synAndDealData(startTime, endTime);
} catch (InterruptedException e) {
e.printStackTrace();
} catch (AppException e) {
e.printStackTrace();
}
}
public static Object getInstance(String serviceName){
//直接从配置文件中注入service类
if (null==context) {
context = ContextLoaderListener.getCurrentWebApplicationContext();
}
return context.getBean(serviceName);
}
}
//具体调用
EntInfoRunnable e = new EntInfoRunnable(date.getStartDate(), date.getEndDate());
new Thread(e).start();