Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package airport.dispatcher.weather; import java.util.Timer; import java.util.TimerTask; import javax.annotation.PostConstruct; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** * * @author mcdoker */ @Component public class HydrometeorologicalServiceImpl implements HydrometeorologicalService { private final static Logger LOG = Logger.getLogger(HydrometeorologicalServiceImpl.class); private final Timer timerUpdateWeather = new Timer(); private TimerTask timerTaskUpdateWeather; @Autowired private SetWeather weather; private final static long DELAY = 1000; private final static long PERIOD = 10000; public HydrometeorologicalServiceImpl() { } @PostConstruct private void postCreateProcess() { this.weather.update(); startTimerTask(PERIOD); } public void startTimerTask(long period) { timerTaskUpdateWeather = new TimerTask() { @Override public void run() { if (LOG.isInfoEnabled()) { LOG.info("weather update"); } weather.update(); } }; timerUpdateWeather.schedule(timerTaskUpdateWeather, DELAY, period); } @Override public GetWeather getWeather() { if (LOG.isInfoEnabled()) { LOG.info("get weather"); } return weather; } }