修改系统时间延迟修改

back_recharge
lvxinran 2019-06-26 13:40:20 +08:00
parent a9f8d02ece
commit 7ee6ab2961
1 changed files with 30 additions and 4 deletions

View File

@ -8,6 +8,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
@ -15,13 +17,15 @@ import java.util.concurrent.atomic.AtomicInteger;
public class ThreadManager {
private static ThreadManager instance = null;
private static final Logger LOGGER = LoggerFactory.getLogger(ThreadManager.class);
private PlatConfigureTask platConfigureTask;
private static PlatConfigureTask platConfigureTask;
private ScheduledThreadPoolExecutor scheduledExecutor; //管理task
private static volatile ScheduledThreadPoolExecutor scheduledExecutor; //管理task
public void init() {
scheduledExecutor = new ScheduledThreadPoolExecutor(16, new ScheduleThreadFactory());
@ -34,6 +38,14 @@ public class ThreadManager {
go();
}
private ThreadManager(){}
public static synchronized ThreadManager getInstance(){
if(instance==null){
instance = new ThreadManager();
}
return instance;
}
static class ScheduleThreadFactory implements ThreadFactory {
@ -60,7 +72,7 @@ public class ThreadManager {
}
public void go() {
public static void go() {
int now = (int)(System.currentTimeMillis()/1000);
scheduledExecutor = new ScheduledThreadPoolExecutor(16, new ScheduleThreadFactory());
@ -69,8 +81,22 @@ public class ThreadManager {
LOGGER.info("delayForMinute---->>>>{}" ,delayForMinute);
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, PlatConfigureTask.SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new MinuteTask(), delayForMinute, 60, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new Thread(){
public void run () {
long lastMilis = System.currentTimeMillis();
try { Thread.sleep(10000L); } catch (InterruptedException e) { }
long millis = System.currentTimeMillis();
if((millis - lastMilis)-10000>10||(millis - lastMilis)-10000<-10){
reStart();
}
}
}, delayForMinute, 10, TimeUnit.SECONDS);
scheduledExecutor.execute(new RetrySendIndicationThread("retry_send"));
}
public static void reStart(){
LOGGER.info("重启线程池!!");
scheduledExecutor.shutdown();
go();
}
}