cn.acyou.leo.framework.commons.ThreadAsyncCall Maven / Gradle / Ivy
package cn.acyou.leo.framework.commons;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import java.util.Map;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
@Slf4j
public class ThreadAsyncCall {
private static final DelayQueue QUEUE = new DelayQueue<>();
static {
synchronized (ThreadAsyncCall.class) {
log.info("thread async call 初始化");
Thread thread = new Thread(() -> {
try {
while (true) {
if (QUEUE.size() != 0) {
DelayTask task = QUEUE.poll(10, TimeUnit.MINUTES);
try {
if (task != null) {
Map contextMap = task.getContextMap();
MDC.setContextMap(contextMap);
Supplier