我正在开发一个Spring Boot Web应用程序,它使用SWI-Prolog的JPL接口从Java调用Prolog.在开发模式下,一切正常.
当我将其部署到Docker时,通过API对JPL的首次调用运行良好.当我尝试再次调用JPL时,JVM崩溃.
我使用LD_PRELOAD指向libswipl.so
SWI_HOME_DIR也被设置.
LD_LIBRARY_PATH设置为指向libjvm.so
我的控制器功能:
@PostMapping("/rules/testAPI/")
@Timed
public List<String> insertRule() {
String use_module_http = "use_module(library(http/http_open)).";
JPL.init();
Query q1 = new Query(use_module_http);
if (!q1.hasNext()) {
System.out.println("Failed to load HTTP Module");
} else {
System.out.println("Succeeded to load HTTP Module");
}
return null;
}
控制台输出
第一次通话
Succeeded to load HTTP Module
第二次通话
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f31705294b2,pid=16,tid=0x00007f30d2eee700
#
# JRE version: OpenJDK Runtime Environment (8.0_191-b12) (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libswipl.so+0xb34b2] PL_thread_attach_engine+0xe2
#
# Core dump written. Default location: //core or core.16
#
# If you would like to submit a bug report,please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
我将错误日志文件上传到pastebin中. click here
有没有人遇到过同样的问题?有解决办法吗?
请注意,我也使用oracle-java-8进行了检查,但是发生相同的错误.
更新:
@CapelliC答案无效.
最佳答案
我想我会尝试“使用”该术语.例如
原文链接:https://www.f2er.com/spring/531610.htmlQuery q1 = new Query(use_module_http);
if (!q1.hasNext()) {
System.out.println("Failed to load HTTP Module");
} else {
System.out.println("Succeeded to load HTTP Module:"+q1.next().toString());
// remember q1.close() if there could be multiple soultions
}
或更好
if ((new Query(use_module_http)).oneSolution() == null) ...
还是更好
if ((new Query(use_module_http)).hasSolution() == false) ...