Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError: Java heap space

 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();

Logger logger=new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
driver.setLogger(logger);
MessageHandler.setScreenLogger(logger);

driver.setRenderer(org.apache.fop.apps.Driver.RENDER_PDF);
OutputStream out = new java.io.FileOutputStream(pdffile);
driver.setOutputStream(out);

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));

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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Pankaj Chaudhary
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all of u i got solution now bye increasing memory size using environment variable java_opts
 
Manoj Raghuwanshi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic