- From: Laird, Brian <BLaird@perseco.com>
- Date: Mon, 1 Dec 2003 09:28:12 -0600
- To: "Red K" <redkresearch@yahoo.com.sg>, <www-jigsaw@w3.org>
Here are few of my comments / questions on this: 1) What version of the JDK are you using? 2) Can you upgrade to 2.2.3? 3) You need to be sure to do some clean up of all the IO classes. Example, I didn't see a close or destroy for the BufferedImage or the ImageWriter class. 4) You may need to start the JVM with more aggressive memory management. Things like minimum & maximum heap size as well as the garbage collection method. Hope this helps, Brian -----Original Message----- From: Red K [mailto:redkresearch@yahoo.com.sg] Sent: Friday, November 28, 2003 2:28 AM To: www-jigsaw@w3.org Subject: servlet and memory leakage Hi, dear all: I wrote one servlet on Jigsaw 2.0.5. This servlet draws one graph in memory and writes it the HTTP response as an jpeg image. I notice that every request to the servlet will cause some amount of memory leakage in my Jigsaw server. And if I request it at a higher rate, the Jigsaw server will prompt it runs out of memory. I just learn to use Java. However, I know that Java claims automatic memory leakage prevension. So I am puzzled. Is this problem caused by my poor Java programming or by Jigsaw possible bugs? The servlet is as the following: -------------------------------- import java.io.*; import java.util.*; import javax.servlet.ServletException; import java.io.*; import java.util.*; import javax.imageio.*; import java.awt.image.*; import java.awt.*; import javax.imageio.stream.*; import javax.servlet.ServletOutputStream; import javax.servlet.http.*; public class StockImgServlet extends HttpServlet { int[] A = new int[100]; public void oneRead(String stock, int ratio) throws IOException { //1. read in price list BufferedReader in = new BufferedReader(new FileReader(stock)); int i; for(i=0;i<100;i++) { String line = in.readLine(); Integer value = new Integer(line); A[i] = value.intValue(); } in.close(); } public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { //1. get stock and ratio values String stock = req.getParameter("stock"); String ratio_string = req.getParameter("ratio"); Integer ratio_obj = new Integer(ratio_string); int ratio = ratio_obj.intValue(); //2. set content type res.setContentType("image/jpeg"); res.setHeader("Cache-Control","no-cache"); //3. check stock oneRead(stock,ratio); //4. generate img and dump out BufferedImage img = new BufferedImage(500,250,BufferedImage.TYPE_BYTE_INDEXED); Graphics2D g = img.createGraphics(); int i; for(i=0;i<100;i++) { g.fillRect(i*5,A[i]*5,3,3); } for(i=1;i<100;i++) { g.drawLine((i-1)*5,A[i-1]*5,i*5,A[i]*5); } try { Iterator w = ImageIO.getImageWritersByMIMEType("image/jpeg"); ImageWriter writer = (ImageWriter)w.next(); ImageOutputStream ios = ImageIO.createImageOutputStream((OutputStream)(res.getOutputStream())); writer.setOutput(ios); writer.write(img); ios.close(); } catch(Exception e) { } } } -------------------------------- __________________________________________________ Do You Yahoo!? Faster. Easier. Search Contest. http://sg.yahoo.com/search ************************************************************************ This e-mail and any accompanying documents or files contain information that is the property of Perseco, that is intended solely for those to whom this e-mail is addressed (i.e., those identified in the "To" and "Cc" boxes), and that is confidential, proprietary, and/or privileged. If you are not an intended recipient of this e-mail, you are hereby notified that any viewing, use, disclosure, forwarding, copying, or distribution of any of this information is strictly prohibited and may be subject to legal sanctions. If you have received this e-mail in error, please notify the sender immediately of any unintended recipients, and delete the e-mail, all attachments, and all copies of both from your system. While we have taken reasonable precautions to ensure that any attachments to this e-mail have been swept for viruses, we cannot accept liability for any damage sustained as a result of software viruses. ************************************************************************
Received on Monday, 1 December 2003 10:26:08 UTC