首页 > 解决方案 > 用于在启动时插入数据的并行流

问题描述

我只是想知道是否可以在启动事件函数中创建一个 parallelStream。我现在发现了 quarkus,为了进行测试,我必须在启动时读取一个文件并将其文件插入到数据库中。每当尝试使用 aparallelStream而不是普通的时,我都会得到ACCESS_VIOLATION_EXCEPTION.

这是一些代码,因此您可以想象我在做什么。这个例子有效。

void onStart(@Observes StartupEvent ev) throws Exception {
    // Parsing the file, getting the iterator
    it.readAll().stream().forEach(this::operateEntry);
}

@Transactional
void operateEntry(Entry entry) {
    // Performing the database actions for a single entry
}

使用相同的示例,但这次使用并行流会导致错误:

void onStart(@Observes StartupEvent ev) throws Exception {
    // Parsing the file, getting the iterator
    it.readAll().parallelStream().forEach(this::operateEntry);
}

和错误信息

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00007ffd5e59bf40, pid=15880, tid=20388
#
# JRE version: Java(TM) SE Runtime Environment (11.0.1+13) (build 11.0.1+13-LTS)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (11.0.1+13-LTS, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# V  [jvm.dll+0x1ebf40]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\knowledge\curator-service\target\hs_err_pid15880.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp

我知道在每个 quarkus 启动时解析大量数据可能不是一个现实的用例。但是我想了解为什么这不起作用。我很感谢任何建议。

先感谢您。

标签: javaquarkus

解决方案


推荐阅读