Я должен отметить, что все связанные bean-компоненты во всей ситуации (от REST до последней службы) являются ApplicationScoped, за исключением Singleton EJB, который Я попытался вывести из уравнения исключить как возможность, но проблема все еще сохраняется.
Мой код выглядит примерно так:
Код: Выделить всё
@ApplicationScoped
public class BusinessService {
private @Inject RowConverter RowConverter;
private @Resource ManagedExecutorService managedExecutorService;
public void process(InputStream fileInputStream) {
try (Workbook workbook = WorkbookFactory.create(fileInputStream)) {
Sheet sheet = workbook.getSheetAt(0);
Iterator iterator = IteratorUtils.filteredIterator(sheet.rowIterator(), row -> row.getRowNum() > 0 && row.getCell("FOOBAR", Row.MissingCellPolicy.RETURN_BLANK_AS_NULL) != null);
}
Map requests = getRequestsMap(IteratorUtils.toList(iterator));
List callables = ListUtils.partition(rows, Math.max(300, rows.size() / 10)).stream()
.map(partition -> new RowToMyWrapperObjCallable(partition, rowConverter))
.collect(Collectors.toList());
return managedExecutorService.invokeAll(callables).stream()
.flatMap(future -> {
try {
return future.get();
} catch (InterruptedException e) {
log.error("Error processing XLSX file", e);
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
log.error("Error processing XLSX file", e);
}
throw new GenericException("Error processing commissions XLSX file", ErrorCode.FILE_PROCESSING_ERROR);
}).collect(Collectors.groupingBy(r -> isRequestValid(r) ? RequestValidity.VALID : RequestValidity.INVALID));
}
}
// ------------------------------------------------------------------------------------------------ //
@RequiredArgsConstructor
public class RowToMyWrapperObjCallable implements Callable {
private final List rows;
private final RowConverter mapper;
@Override
public Stream call() throws Exception {
log.info("Running mapping on thread: {}", Thread.currentThread().getName());
return rows.stream().map(mapper);
}
}
// ------------------------------------------------------------------------------------------------ //
@ApplicationScoped
public class RowConverter implements Function {
@Override
public MyWrapperObj apply(Row row) {
log.info("[{}] RowConverter::apply", Thread.currentThread().getName());
// do the mapping
}
}
Код: Выделить всё
2024-12-06 00:46:57.968+0200 INFO RowToMyWrapperObjCallable.call(Line 28) [pool-59-thread-1](523) [] Running mapping on thread: pool-59-thread-1
2024-12-06 00:46:57.968+0200 INFO RowToMyWrapperObjCallable.call(Line 28) [pool-59-thread-3](525) [] Running mapping on thread: pool-59-thread-3
2024-12-06 00:46:57.969+0200 INFO RowToMyWrapperObjCallable.call(Line 28) [pool-59-thread-4](526) [] Running mapping on thread: pool-59-thread-4
2024-12-06 00:46:57.968+0200 INFO RowToMyWrapperObjCallable.call(Line 28) [pool-59-thread-2](524) [] Running mapping on thread: pool-59-thread-2
2024-12-06 00:47:00.633+0200 INFO RowConverter.apply(Line 60) [http-thread-pool::http-listener-1(1)](149) [] [http-thread-pool::http-listener-1(1)] RowConverter::apply
2024-12-06 00:47:00.889+0200 INFO RowConverter.apply(Line 60) [http-thread-pool::http-listener-1(1)](149) [] [http-thread-pool::http-listener-1(1)] RowConverter::apply
2024-12-06 00:47:01.084+0200 INFO RowConverter.apply(Line 60) [http-thread-pool::http-listener-1(1)](149) [] [http-thread-pool::http-listener-1(1)] RowConverter::apply
Подробнее здесь: https://stackoverflow.com/questions/792 ... microprofi
Мобильная версия