Multithreading support

Contents
[ ]

Aspose.OCR for Java allows you to limit the number of threads used by the recognition engine. This may slow down the recognition speed, but will allow you to reserve some resources for other processes such as the parallel image processing, web server, database management system, or background data analysis.

To set the number of threads, use setThreadsCount method of the RecognitionSettings class.

  • If you specify 0 or do not set this parameter, the recognition engine will use all CPU cores.
  • If you specify 1, recognition will be performed on the application’s main thread.
AsposeOCR api = new AsposeOCR();
// Add images to the recognition batch
OcrInput images  = new OcrInput(InputType.SingleImage);
images.add("image1.png");
images.add("image2.png");
// Limit recognition load to 2 threads
RecognitionSettings recognitionSettings = new RecognitionSettings();
recognitionSettings.setThreadsCount(2);
// Recognize images
ArrayList<RecognitionResult> results = api.Recognize(images, recognitionSettings);
results.forEach((result) -> {
	System.out.println("Recognition result:\n" + result.recognitionText + "\n\n");
});