并发解决方案
private LinkedBlockingDeque<Request> queue = new LinkedBlockingDeque();
@Data
class Request{
UseLogDto dto;
CompletableFuture<Integer> future;
public Request(AppUseLogDto dto,CompletableFuture<Integer> future){
this.dto = dto;
this.future = future;
}
}
public int saveLog(UseLogDto logDto) throws Exception {
CompletableFuture<Integer> future = new CompletableFuture();
Request request = new Request(logDto,future);
queue.add(request);
return future.get();
}
@Async
@Scheduled(cron = "*/2 * * * * ?")
public void logTask() throws Exception {
int status = 0;
List<Request> requests = new ArrayList<>();
try {
int size = queue.size();
log.info("扫描发队列长度:" + size);
if (size == 0){
return;
}
List<Ap