- From: Red K <redkresearch@yahoo.com.sg>
- Date: Fri, 28 Nov 2003 16:27:57 +0800 (CST)
- To: www-jigsaw@w3.org
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
Received on Friday, 28 November 2003 03:29:57 UTC