package egovframework.scheduler; import egovframework.service.impl.CommonServiceImpl; import egovframework.utill.TrafficData; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import java.text.SimpleDateFormat; import java.util.Date; @Slf4j @RequiredArgsConstructor @EnableScheduling @Component public class TrafficSchedule { private final CommonServiceImpl cs; public String getSysTime() { SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date dtLog = new Date(); return sdfDate.format(dtLog); } @Scheduled(cron = "0 0/5 * * * ?") // 5분주기 작업 실행 public void trafficSchedule() { log.info("Traffic Schedule Work Time : {}", getSysTime()); TrafficData.setRoad(this.cs.getRoadVertexArr()); TrafficData.setIfsc(this.cs.getIfscVertexArr()); TrafficData.setLink(this.cs.getLinkVertexArr()); } @PostConstruct private void init() { log.info("Traffic Schedule init : {}", getSysTime()); TrafficData.setRoad(this.cs.getRoadVertexArr()); TrafficData.setIfsc(this.cs.getIfscVertexArr()); TrafficData.setLink(this.cs.getLinkVertexArr()); } @PreDestroy public void preDestroy() { } }