ScheduledExecutorService
JDK 1.5 之后自带的 API java.util.concurrent 提供的API ,不会造成任务间的相互影响。
第一个参数为执行体,第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@Component
public class SxScheduledExecutor implements ApplicationListener {
private static org