【发布时间】:2015-01-20 10:20:19
【问题描述】:
我第一次将 Jfreechart (jfreechart-1.0.13.jar) 与 struts1、java6、jboss4 一起使用。 我使用此代码创建图表:
private JFreeChart getJfreeChart(int product, int msg) {
DefaultPieDataset dpd = new DefaultPieDataset();
dpd.setValue("product", product);
dpd.setValue("msg", msg);
JFreeChart chart = ChartFactory.createPieChart3D(null, dpd, true, false, false);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setSectionPaint("product", new Color(51, 102, 153));
plot.setSectionPaint("msg", new Color(160, 218, 230));
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}"));
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} : {1}"));
return chart;
}
在我的操作中,我确实喜欢这样显示图表:
response.setContentType("image/png");
ServletOutputStream outputStream = response.getOutputStream();
ChartUtilities.writeChartAsPNG(outputStream, chart, 900, 450);
outputStream.close();
在我的jsp中,我使用<img src="MyAction.do" />来显示图表
当我执行 getJfreeChart 时,我注意到内存泄漏。 我的代码有异常吗?
java.lang.OutOfMemoryError: PermGen space
at javax.swing.UIManager.initialize(Unknown Source)
at javax.swing.UIManager.maybeInitialize(Unknown Source)
at javax.swing.UIManager.getDefaults(Unknown Source)
at javax.swing.UIManager.getColor(Unknown Source)
at org.jfree.chart.JFreeChart.<clinit>(JFreeChart.java:261)
at org.jfree.chart.ChartFactory.createPieChart3D(ChartFactory.java:763)
【问题讨论】:
-
内存不足并不一定表示“泄漏”。您的 PermGen 空间的大小设置为多少?该 JVM 实例上还运行什么?
-
@Mikaveli :我有这个配置: -XX:PermSize=258M -XX:MaxPermSize=512M 只有应用程序在 JVM 实例上运行。
标签: java jboss jfreechart struts-1