Java 对于不同的文档,apachefop是线程安全的吗
我正在开发一个Spring引导应用程序,它应该使用XSLT将XML转换为PDF。 我想使用ApacheFop,但它在自己的文档中声明() Apache FOP目前可能不是完全线程安全的。该代码尚未针对多线程问题进行全面测试 不幸的是,这些文档并没有告诉我们什么是尚未测试的。是否可以并行地将几个独立的XML转换为几个独立的PDF(使用多个CPU核)Java 对于不同的文档,apachefop是线程安全的吗,java,multithreading,xslt,pdf-generation,apache-fop,Java,Multithreading,Xslt,Pdf Generation,Apache Fop,我正在开发一个Spring引导应用程序,它应该使用XSLT将XML转换为PDF。 我想使用ApacheFop,但它在自己的文档中声明() Apache FOP目前可能不是完全线程安全的。该代码尚未针对多线程问题进行全面测试 不幸的是,这些文档并没有告诉我们什么是尚未测试的。是否可以并行地将几个独立的XML转换为几个独立的PDF(使用多个CPU核) private URI convertToPDF(byte[] body, byte[] xsl, String pdfFileName) throw
private URI convertToPDF(byte[] body, byte[] xsl, String pdfFileName) throws Exception {
File pdfFile = new File(saveDirectory, pdfFileName);
FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
// Setup output
try(BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(pdfFile));) {
// Construct fop with desired output format
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(new ByteArrayInputStream(xsl)));
// Setup input for XSLT transformation
Source src = new StreamSource(new ByteArrayInputStream(body));
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
return pdfFile.toURI();
}
}
Configuration
public class ConverterConfig {
@Bean
public FopFactory fopFactory() {
return FopFactory.newInstance(new File(".").toURI());
}
}