]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-2874: Conserve memory policy fails in multi-threaded environment
authorSimon Steiner <ssteiner@apache.org>
Tue, 23 Jul 2019 10:41:07 +0000 (10:41 +0000)
committerSimon Steiner <ssteiner@apache.org>
Tue, 23 Jul 2019 10:41:07 +0000 (10:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1863625 13f79535-47bb-0310-9956-ffa450edef68

fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java
fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java

index e5c6f5b2bb74ca919faba87369ff4147000a28d7..d3ae2e25d49ada171c5208d0748f6f35d27392d1 100644 (file)
@@ -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 {
index f4dcd7ef2e3cac7e437c9148d214f0cdcedacf87..b8bca13e47314e7aeee9eb06891ac5e266282be7 100644 (file)
@@ -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 = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
+    public void testLink() throws Throwable {
+        final String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
                 + "  <fo:layout-master-set>\n"
                 + "    <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n"
                 + "      <fo:region-body />\n"
@@ -51,7 +54,26 @@ public class ConserveMemoryTestCase {
                 + "    </fo:flow>\n"
                 + "  </fo:page-sequence>\n"
                 + "</fo:root>";
-        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 {