我在我的java应用程序中使用Tess4j 3.0.0和Tesseract 3.04。 在我的应用程序中,我为OCR创建了一个实现Runnable的服务。
应用程序部署在Centos 6中
以下代码在服务中。
Tesseract1 instance = new Tesseract1();
result = instance.doOCR("pathtodocument/abc.pdf");
我根据用户的请求从文档上传服务启动OCR服务的线程,并处理来自PDF的文本数据。
当我测试单个请求的代码时,它完美无缺。 问题是: 当我一次发送多个请求时,整个应用程序崩溃。
以下是catalina.out中的错误
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f9514000078, pid=12979, tid=140277704374016
#
# JRE version: Java(TM) SE Runtime Environment (8.0_74-b02) (build 1.8.0_74-b02)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.74-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C 0x00007f9514000078
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# //hs_err_pid12979.log
#
# If you would like to submit a bug report, please visit:
当我在服务上放置调试器并执行应用程序时,一切正常。
答案 0 :(得分:1)
为Tesseract1创建bean
@Bean
public Tesseract1 tesseract() {
return new Tesseract1();
}
in Service:autowire Tesseract
@Autowire
private Tesseract1 instance;
将doOcr方法放在synchronized块
中syncrhonized(instance){
String result = instance.doOCR(imageFile);
//other stuff
}
现在,服务线程将在不崩溃应用程序的情况下运行。
注意:我们正在丢失并发OCR以同时处理文档。