Hello
using Aspose PDF for Java 24.5
we want to use PdfFileEditor split functions in multi threaded code.
It seems that even if you use own instances for the threads you have side effects between the objects.
Code sample:
public void splitAllMulti(String srcDoc, String destDir) throws IOException, InterruptedException, ExecutionException {
int parallelism = 2;
ForkJoinPool customThreadPool = new ForkJoinPool(parallelism);
String fname = destDir + "/" + FilenameUtils.getBaseName(srcDoc);
ArrayList<Integer> stream = new ArrayList<>();
stream.add(0);
stream.add(1);
customThreadPool.submit(() ->
stream.parallelStream().forEach(i -> {
PdfFileEditor pdfEditor2 = new com.aspose.pdf.facades.PdfFileEditor();
pdfEditor2.setCopyLogicalStructure(true);
pdfEditor2.setOptimizeSize(true);
String destName = fname + "_" + i + "_%NUM%.pdf";
pdfEditor2.splitToPages(srcDoc, destName);
pdfEditor2 = null;
})
).get();
}
If you run this code on a large PDF (eg 100 plus pages)
you get exceptions:
*Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7*
*at com.aspose.pdf.internal.l2f.l1v.lI(Unknown Source)*
*at com.aspose.pdf.internal.l2f.l1v.lj(Unknown Source)*
*at com.aspose.pdf.PageCollection.delete(Unknown Source)*
*at com.aspose.pdf.PageCollection.delete(Unknown Source)*
*at com.aspose.pdf.facades.APdfFileEditor.lI(Unknown Source)*
*at com.aspose.pdf.facades.APdfFileEditor.splitToPages(Unknown Source)*
*at com.aspose.pdf.facades.PdfFileEditor.splitToPages(Unknown Source)*
Is the class PdfFileEditor ready to be used in a multi thread scenario?
What do we need to consider?
kind regards
Sascha