package com.highdatas.mdm.util;
|
|
import com.highdatas.mdm.service.DispenseService;
|
import com.highdatas.mdm.util.pool.MqMessage;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Configuration;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import java.io.IOException;
|
import java.util.Date;
|
import java.util.concurrent.PriorityBlockingQueue;
|
|
/**
|
* @author kimi
|
* @description
|
* @date 2020-04-15 13:25
|
*/
|
|
|
@Configuration
|
@EnableScheduling
|
@Slf4j
|
public class TimeTasks {
|
@Autowired
|
DispenseService dispenseService;
|
|
@Scheduled(fixedRate=1000 * 10)
|
private void configureTasks() {
|
PriorityBlockingQueue<Runnable> queue = dispenseService.getQueue();
|
if (queue.isEmpty()) {
|
return;
|
}
|
log.info("queue passiveQueueSize: {}", queue.size());
|
for (Runnable runnable : queue) {
|
if (!(runnable instanceof MqMessage)) {
|
continue;
|
}
|
MqMessage mqMessage = (MqMessage) runnable;
|
Date endTime = mqMessage.getEndTime();
|
Date now = new Date();
|
if (now.after(endTime)) {
|
//timeout;
|
try {
|
mqMessage.printTimeOut();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
}
|
}
|