java110
2023-06-05 6965916e5ef0c83b8ea4a8001be21e6f0f274a69
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
package com.java110.job.export;
 
import com.java110.core.log.LoggerFactory;
import com.java110.dto.data.ExportDataDto;
import org.slf4j.Logger;
 
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
 
public class ExportDataQueue {
    private static final Logger log = LoggerFactory.getLogger(ExportDataQueue.class);
 
    private static final BlockingQueue<ExportDataDto> msgs = new LinkedBlockingQueue<ExportDataDto>(100);
 
    /**
     * 添加导出数据消息
     *
     * @param exportDataDto
     */
    public static void addMsg(ExportDataDto exportDataDto) {
        try {
 
            msgs.offer(exportDataDto,3, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            log.error("写入队列失败", e);
            e.printStackTrace();
        }
    }
 
    public static ExportDataDto getData() {
        try {
            return msgs.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;
    }
 
}