I have problem when i have to print 1500 pdf file concurently.the message shown on browser is "java.lang.OutOfMemoryError: Java heap space".this message is shown after 100 printing of pdf file.Plz help me in this topic
hiii , i m using following code in action servlet for making pdf
File xsltfile = new File("../webapps"+path+"/resources/xsls/admin/totalpayout.xsl"); File pdffile = new File("../webapps"+path+"/resources/pdfs/admin/totalpayout.pdf"); org.apache.fop.apps.Driver driver = new org.apache.fop.apps.Driver();
Source src = new StreamSource("../webapps"+path+"/resources/xmls/admin/totalpayout.xml");
//Resulting SAX events (the generated FO) must be piped through to FOP Result result = new SAXResult(driver.getContentHandler()); transformer.transform(src, result);
Author and all-around good cowpoke
Joined: Mar 22, 2000
So you are really talking about generating PDF files in a servlet, not "printing."
Generating PDF just naturally takes a lot of memory since FOP has to create an entire representation of each document in memory. You should approach this problem by either: 1. Giving the servlet engine enough memory -or- 2. Restricting the number of simultaneous generation threads running. -or- a combination of both. Also, be sure that your code does not hold on to references to objects after the PDF has been generated. Bill
And indeed, generating 1500 different PDFs concurrently still sounds excessive. To expand on Bill's "2. Restricting the number of simultaneous generation threads running" - I would consider using a thread pool, with a max size that you can configure. Thus you can limit the number of jobs which can truly proceed concurrently, which allows you to avoid the OutOfMemoryError and may also improve performance. Even if memory were infinite, the more simultaneous threads you have going, the more time is spent simply switching from one thread to another. You reach a point of dimiinishing returns where it becomes more efficient to finish some of the jobs you have already, before adding new threads.
Note that in JDK 5 and beyond, you can use ThreadPoolExecutor and related classes to manage a thread pool with a minimum of hassle. For earlier JDK versions, there are various open-source implementations of thread pooling available. [ June 19, 2006: Message edited by: Jim Yingst ]
"I'm not back." - Bill Harding, Twister
Joined: Jun 05, 2006
thanks all of u i got solution now bye increasing memory size using environment variable java_opts
When I saw Pankaj�s post first , I wonder how he can able to print PDF from java.Because I spent 1 month on searching how to print pdf from java and then came to conclusion that it is not possible without taking help of a third party library like Icepdf. Any one knows whether Sun has added support for printing pdf files in new java versions?