Исправил обработку InterruptedException.
This commit is contained in:
psemenkov 2023-04-25 11:49:26 +03:00
parent 510dfde848
commit 7543e4b08f
2 changed files with 16 additions and 5 deletions

View file

@ -1,9 +1,12 @@
package ru.spcex.clearing.scheduler.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import ru.clearing.classes.statics.data.scheduler.PlannerAllToday;
import ru.spcex.clearing.scheduler.service.TaskManager;
import ru.spcex.platform.utils.log.ExceptionUtils;
import java.util.Map;
import java.util.concurrent.BlockingQueue;
@ -11,6 +14,7 @@ import java.util.concurrent.LinkedBlockingQueue;
@Configuration
public class PlannerQueueConfig {
private static final Logger log = LoggerFactory.getLogger(TaskManager.class);
private static BlockingQueue<Map.Entry<TaskManager.Process, PlannerAllToday>> plannerQueue;
@ -23,7 +27,9 @@ public class PlannerQueueConfig {
public static void addToPlannerQueue(TaskManager.Process process, PlannerAllToday plannerAllToday) {
try {
plannerQueue.put(Map.entry(process, plannerAllToday));
} catch (InterruptedException ignored) {
} catch (InterruptedException e) {
log.warn("InterruptedException plannerQueue.put {}", ExceptionUtils.getStackTrace(e));
Thread.currentThread().interrupt();
}
}
}

View file

@ -14,6 +14,7 @@ import ru.spcex.platform.enumeration.Status;
import ru.spcex.platform.enumeration.Task;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.log.ExceptionUtils;
import java.time.*;
import java.util.*;
@ -79,14 +80,17 @@ public class TaskManager implements InitializingBean, AutoCloseable {
private void process() {
outputExecutor.submit(() -> {
try {
while (!closed.get()) {
while (!closed.get()) {
try {
//процесс ожидает пока появится новое сообщение в очереди
Map.Entry<Process, PlannerAllToday> entry = plannerQueue.take();
callbacks.get(entry.getKey()).accept(entry.getValue());
} catch (InterruptedException e) {
closed.set(true);
Thread.currentThread().interrupt();
} catch (Throwable t) {
log.error("InterruptedException in process, {}", ExceptionUtils.getStackTrace(t));
}
} catch (InterruptedException e) {
// closed.set(true);
}
});
}
@ -246,5 +250,6 @@ public class TaskManager implements InitializingBean, AutoCloseable {
public void close() {
log.debug("Closing task manager {}", getClass().getSimpleName());
closed.set(true);
outputExecutor.shutdown();
}
}