From: Simon Steiner Date: Tue, 23 Jul 2019 10:41:07 +0000 (+0000) Subject: FOP-2874: Conserve memory policy fails in multi-threaded environment X-Git-Tag: fop-2_4~14 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7c3a62ee56aa954a6c9c42f5da93e33763848d88;p=xmlgraphics-fop.git FOP-2874: Conserve memory policy fails in multi-threaded environment git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1863625 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java b/fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java index e5c6f5b2b..d3ae2e25d 100644 --- a/fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java +++ b/fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java @@ -123,8 +123,8 @@ public class CachedRenderPagesModel extends RenderPagesModel { try { // save page to cache ObjectOutputStream tempstream; - String fname = "fop-page-" + page.getPageIndex() + ".ser"; - URI tempURI = tempBaseURI.resolve(fname); + String fname = "/fop-page-" + page.getPageIndex() + ".ser"; + URI tempURI = URI.create(tempBaseURI + fname); OutputStream outStream = renderer.getUserAgent().getResourceResolver().getOutputStream(tempURI); tempstream = new ObjectOutputStream(new BufferedOutputStream(outStream)); try { diff --git a/fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java b/fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java index f4dcd7ef2..b8bca13e4 100644 --- a/fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java @@ -19,6 +19,9 @@ package org.apache.fop.render; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; import javax.xml.transform.Result; import javax.xml.transform.Source; @@ -38,8 +41,8 @@ import org.apache.fop.apps.FopFactory; public class ConserveMemoryTestCase { @Test - public void testLink() throws TransformerException, SAXException { - String fo = "\n" + public void testLink() throws Throwable { + final String fo = "\n" + " \n" + " \n" + " \n" @@ -51,7 +54,26 @@ public class ConserveMemoryTestCase { + " \n" + " \n" + ""; - foToOutput(fo); + + ExecutorService es = Executors.newCachedThreadPool(); + final Throwable[] ex = new Throwable[1]; + for (int i = 0; i < 5; i++) { + Runnable thread = new Runnable() { + public void run() { + try { + foToOutput(fo); + } catch (Throwable e) { + ex[0] = e; + } + } + }; + es.execute(thread); + } + es.shutdown(); + es.awaitTermination(1, TimeUnit.MINUTES); + if (ex[0] != null) { + throw ex[0]; + } } private void foToOutput(String fo) throws SAXException, TransformerException {