summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2019-07-23 10:41:07 +0000
committerSimon Steiner <ssteiner@apache.org>2019-07-23 10:41:07 +0000
commit7c3a62ee56aa954a6c9c42f5da93e33763848d88 (patch)
tree18280cacda182a1452a9296b48412e760d15a61e
parentdbad6491f8f880297ae3a612060d123825baed83 (diff)
downloadxmlgraphics-fop-7c3a62ee56aa954a6c9c42f5da93e33763848d88.tar.gz
xmlgraphics-fop-7c3a62ee56aa954a6c9c42f5da93e33763848d88.zip
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
-rw-r--r--fop-core/src/main/java/org/apache/fop/area/CachedRenderPagesModel.java4
-rw-r--r--fop-core/src/test/java/org/apache/fop/render/ConserveMemoryTestCase.java28
2 files changed, 27 insertions, 5 deletions
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 = "<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 {