为有中文需求的客户提供多渠道中文技术支持.

Fri Jun 07, 2024 8:16 am

请问 OcrScanner 这个类是现成安全的么?多线程情况下能安全试用么?

还有如下使用全局唯一的实例 scanner 可以么?
Code: Select all
public class OcrAccessor {

    private static  OcrScanner scanner ;


    public static String[] win = new String[]{"libiomp5md.dll","mkldnn.dll"
            ,"mklml.dll","opencv_world3416.dll","spire_ocrlib.dll","spire_ocrsystem.dll"};


    public static String[] linux = new String[]{"libdnnl.so.1","libiomp5.so","libmkldnn.so.0","libmklml_intel.so","libspire_ocrsystem.so"};


    private OcrAccessor(){

    }



    public static void init() {
        try{
            String[] dependencies;
            String osName = System.getProperty("os.name").toLowerCase();
            if (osName.contains("win")) {
                dependencies = win;
            } else {
                dependencies = linux;
            }
            var path = dependencyPath(dependencies);

            log.info("依赖路径:{}",path);

            scanner = new OcrScanner();

            scanner.setDependencies(path);


        }catch (Exception e){

            log.error("OCR 初始化失败",e);
        }

    }
}

pengpengOn
 
Posts: 1
Joined: Fri Jun 07, 2024 1:03 am

Fri Jun 07, 2024 10:25 am

您好,

感谢您的来信。
为了避免多线程安全问题,我们建议您在每个线程中单独实例化OcrScanner 对象。

Sincerely
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to 中文技术支持