kimi
2020-04-15 5d15287b2a06f978485ac6af71e33e1a82b43a65
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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();
                }
            }
        }
    }
}