Open omasseau opened 7 years ago
Test code to reproduce the problem:
public static void main(String[] args) throws Exception {
String input = "C:/Users/maol/Developments/AOF/Tests/pdf/pdf-images/16-pages-of-text-image.pdf";
final ByteArrayInputStream bais1 = new ByteArrayInputStream(Files.readAllBytes(Paths.get(input)));
final ByteArrayInputStream bais2 = new ByteArrayInputStream(Files.readAllBytes(Paths.get(input)));
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
Thread t1 = new Thread() {
public void run() {
try {
convertPdfToPostscript(bais1, baos1);
} catch (Exception e) {
e.printStackTrace();
}
}
};
Thread t2 = new Thread() {
public void run() {
try {
convertPdfToPostscript(bais2, baos2);
} catch (Exception e) {
e.printStackTrace();
}
}
};
t1.start();
t2.start();
}
Tested with both Java7 and Java8
I'm using the high level API with the latest version of ghost4j (built from Latest commit 52cd8f2 on 5 May 2016) to convert pdfs to postscript The documentation says the high level API is thread safe.
But this does not seems the case. Here is my code:
But I still get an 'Invalid memory access' error when calling it from 2 threads at the same time:
java.lang.Error: Invalid memory access at com.sun.jna.Native.invokeInt(Native Method) at com.sun.jna.Function.invoke(Function.java:383) at com.sun.jna.Function.invoke(Function.java:315) at com.sun.jna.Library$Handler.invoke(Library.java:212) at com.sun.proxy.$Proxy202.gsapi_init_with_args(Unknown Source) at org.ghost4j.Ghostscript.initialize(Ghostscript.java:350) at org.ghost4j.converter.PSConverter.run(PSConverter.java:142) at org.ghost4j.converter.AbstractRemoteConverter.convert(AbstractRemoteConverter.java:85) at com.real.aof.helper.PdfHelper.convertPdfToPostscript(PdfHelper.java:2573)