我已经通过以下命令从命令行启动了我的jar
文件:
java -Xms1200m -Xmx1500m -jar xxx.jar
我正在创建尺寸为12600 * 12600的BufferedImage,这意味着以下代码需要使用606 MB内存。
TranscoderInput input = new TranscoderInput(sr);
String pngFile = "Style-" + shoeViewer.getCurrentStyle() + "_"
+ shoeViewer.getSelectedMetadata().getSizeLabel()
+ "_400DPI" + ".png";
File outputFile = new File(pngFile);
FileOutputStream fo = new FileOutputStream(outputFile);
TranscoderOutput output = new TranscoderOutput(fo);
long now = System.currentTimeMillis();
t.transcode(input, null);
在执行以上代码之前,当我调试内存使用情况时,我的运行时显示:
我需要 606 MB 的内存,而 1100 MB 仍然可用。
所以当我在 34 分钟后运行以上代码时,它会抛出 OutOfMemory
异常。
问题是什么?是进程问题还是堆问题?为什么要花费 34 分钟?
我的 PC 配置如下:
Windows 32bit XP Service Pack2 Home Edition
Amd Athlon (tm) 7750 Dual Core 2.71 GHz
2GB of DDR2 RAM
java version "1.7.0_17"
Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode, sharing)
请帮我解决这个问题。
以下是具有调试消息的异常堆栈跟踪。
在运行上述代码之前,我更改了VM参数如下:
java -Xms900m -Xmx1024m -XX:MinHeapFreeRatio=40 -XX:MaxHeapFreeRatio=70 -jar myjar.jar
从SVG Reader构建XML文档......
XML文档从SVG Reader构建完成......
将修改后的XML文档转换为字符串编写器......
修改后的XML文档成功转换为字符串编写器......
已声明字节数766,可用字节数900189232
内存统计------------------------
总内存大小为字节:912326656 总内存大小为兆字节:870
已使用的内存大小为字节:9308384 已使用的内存大小为兆字节:8
可用的空闲内存大小为字节:900189096 可用的空闲内存大小为兆字节:858
转码开始时间:2013年3月24日星期日11:09:59 IST
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap spa
ce
at java.awt.image.DataBufferInt.<init>(Unknown Source)
at java.awt.image.SinglePixelPackedSampleModel.createDataBuffer(Unknown
Source)
at java.awt.image.Raster.createWritableRaster(Unknown Source)
at org.apache.batik.gvt.renderer.StaticRenderer.updateWorkingBuffers(Sta
ticRenderer.java:536)
at org.apache.batik.gvt.renderer.StaticRenderer.repaint(StaticRenderer.j
ava:375)
at org.apache.batik.gvt.renderer.StaticRenderer.repaint(StaticRenderer.j
ava:344)
at org.apache.batik.transcoder.image.ImageTranscoder.transcode(ImageTran
scoder.java:111)
at org.apache.batik.transcoder.XMLAbstractTranscoder.transcode(XMLAbstra
ctTranscoder.java:142)
at org.apache.batik.transcoder.SVGAbstractTranscoder.transcode(SVGAbstra
ctTranscoder.java:156)
at com.mmg.app.eventlistener.PlaceOrderActionListener.save(PlaceOrderAct
ionListener.java:302)
at com.mmg.app.eventlistener.PlaceOrderActionListener.saveCanvas(PlaceOr
derActionListener.java:270)
at com.mmg.app.eventlistener.PlaceOrderActionListener.actionPerformed(Pl
aceOrderActionListener.java:143)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Sour
ce)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
t
是什么类型的对象? - ecbrodie