2016-06-15 16 views
0

我在我的Java應用程序中使用Tess4j 3.0.0與Tesseract 3.04。 在我的應用程序中,我創建了一個實現Runnable的OCR服務。Tesseract 3.0與Tess4j在Linux服務器上崩潰的應用程序

應用程序部署在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

你可以嘗試使用圖像,看看是否也發生圖像相同類型的問題?這似乎是與Tess4j內部使用的Ghost4j相關的問題。你可以啓用核心轉儲併發布該轉儲的更多細節。發佈你的'hs_err_pid12979.log'。如果這與Ghost4j有關,那麼您需要同步處理,因爲Ghost4j不支持多線程。 –

+0

謝謝@ sangram-jadhav。這確實與Ghost4j有關。 現在我已經把Tesseract代碼放入同步塊中。稍後我會執行隊列。我編輯了上面在多線程環境中工作的代碼,而且不會崩潰應用程序。我完全需要在線程中使用這段代碼。 –

回答

0

創造豆爲Tesseract1

@Bean 
public Tesseract1 tesseract() { 
    return new Tesseract1(); 
} 

在服務:自動裝配的Tesseract

@Autowire 
private Tesseract1 instance; 

把doOcr方法synchronized塊

syncrhonized(instance){ 
    String result = instance.doOCR(imageFile); 
    //other stuff 
} 

現在服務線程將沒有崩潰的應用程序內運行。

注意:我們正在丟失同步文檔請求的併發OCR。

+0

謝謝你的回答,你能否詳細說明如何創建將直接在裏面有Tesseract實例的bean?謝謝 –

相關問題