Код: Выделить всё
class myClass1 {
void addToQueue() {
logger.info("adding to queue");
myClass2.add(trade);
}
}
Код: Выделить всё
class myClass2 {
ConcurrentLinkedQueue executionQueue = new ConcurrentLinkedQueue();
Trade tradeInExecution;
void add(Trade: trade) {
executionQueue.add(trade);
}
void execute() {
var tradeInExecution = executionQueue.poll();
if (tradeInExecution == null) {
return;
}
logger.info("executing");
// do some processing
}
}
Код: Выделить всё
import org.springframework.scheduling.TaskScheduler;
@Component
public class CustomTaskScheduler {
private final TaskScheduler taskScheduler;
@PostConstruct
public void scheduleTasks() {
taskScheduler.scheduleWithFixedDelay(myClass2::execute, Instant.now(), Duration.ofMillis(100));
}
}
Проблема иногда возникает в журнале, который я у меня есть «добавление в очередь» и никакого «выполнения» после него. Как такое могло произойти?
Я ожидаю, что каждое «добавление в очередь» в какой-то момент будет иметь «выполнение», но в некоторых случаях «выполнение» отсутствует
Подробнее здесь: https://stackoverflow.com/questions/782 ... ue-in-java