I suspect the problem is because you're accessing the initial document
from multiple threads.
Tilman
Am 23.03.2022 um 09:52 schrieb 1540731...@qq.com.INVALID:
@RequestMapping(value = "/test", method = RequestMethod.GET)
public void test(HttpServletResponse response,
HttpServletRequest request) throws IOException,
InterruptedException {
logger.info("==========test============");
String path = "H:\\dd\\pdf\\a\\韩顺平_循序渐进学Java零基础【完整笔记】.pdf";
String toPath1 = "H:\\dd\\pdf\\a\\韩顺平_循序渐进学Java零基础【完整笔记】test1.pdf";
String toPath2 = "H:\\dd\\pdf\\a\\韩顺平_循序渐进学Java零基础【完整笔记】test2.pdf";
String toPath3 = "H:\\dd\\pdf\\a\\韩顺平_循序渐进学Java零基础【完整笔记】test3.pdf";
PDDocument document = PDDocument.load(new File(path));
PDPageTree pages = document.getPages();
Iterator<PDPage> iterator = pages.iterator();
int numberOfPages = document.getNumberOfPages();
System.out.println("numberOfPages = " + numberOfPages);
CountDownLatch count = new CountDownLatch(3);
new Thread(()->{
PDDocument to = new PDDocument();
for (int i = 0; i < 1000; i++) {
to.addPage(document.getPage(i));
}
try {
System.out.println(to);
to.save(toPath1);
to.close();
} catch (IOException e) {
e.printStackTrace();
}
count.countDown();
}).start();
new Thread(()->{
PDDocument to = new PDDocument();
for (int i = 0; i < 500; i++) {
to.addPage(document.getPage(i));
}
try {
System.out.println(to);
to.save(toPath2);
to.close();
} catch (IOException e) {
e.printStackTrace();
}
count.countDown();
}).start();
new Thread(()->{
PDDocument to = new PDDocument();
for (int i = 0; i < 100; i++) {
to.addPage(document.getPage(i));
}
try {
System.out.println(to);
to.save(toPath3);
to.close();
} catch (IOException e) {
e.printStackTrace();
}
count.countDown();
}).start();
count.await();
document.close();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: users-h...@pdfbox.apache.org