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
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
Exactly how are you printing pdf files from Java? PDF files on the browser side are handled by the Adobe plugin. Are the PDF files being sent to a browser from a Java servlet? Bill
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);
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12268
1
posted
0
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
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
So you are really talking about generating PDF files in a servlet, not "printing."
And I was already imagining how to print 1500 copies of anything concurrently - that would need to be quite a printer farm!
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
Pankaj Chaudhary
Greenhorn
Joined: Jun 05, 2006
Posts: 16
posted
0
thanks all of u i got solution now bye increasing memory size using environment variable java_opts
Manoj Raghuwanshi
Ranch Hand
Joined: Jun 20, 2004
Posts: 75
posted
0
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?