金麟岂是池中物,一遇风云便化龙
Posts tagged java
让Struts 2性能提升一个数量级的的5个步骤 [zz]
Jan 6th
原文:http://dev.yingzhitech.com/2009/01/06/96
- freemarker 升级为2.3.14
- ognl 升级为 2.7.3(要附加javassis类库)
- 根包下增加freemarker.properties文件,内容为template_update_delay=60000
- struts.xml增加<constant name=”struts.devMode” value=”false”/>和<constant name=”struts.freemarker.templatesCache” value=”true”/>
- 把struts.xml中的默认拦截器定义为basicStack:
<package name="web" extends="tiles-default"> <default-interceptor-ref name="basicStack" /> </package>
执行了这几步之后,网站性能从5 req/s提升至70 req/s,请求处理时间从22s/req缩减至2s/req!
参考连接:
http://struts.apache.org/2.x/docs/performance-tuning.html
http://www.blogjava.net/usherlight/archive/2008/07/01/211869.html
http://www.blogjava.net/usherlight/archive/2008/07/12/214462.html
http://www.blogjava.net/usherlight/archive/2008/09/02/226501.html
如何使用J2D将一张图片灰度化
Dec 10th
可使用以下代码:
Graphics2D g2d = source.createGraphics(); ColorSpace grayCS = ColorSpace.getInstance(ColorSpace.CS_GRAY); ColorConvertOp colorConvertOp = new ColorConvertOp(grayCS, g2d.getRenderingHints()); colorConvertOp.filter(source, source);
其中source为BufferedImage对象
How To Enable Anti-Aliased Globally Since JDK 5
Nov 25th
I just read “Swing Hacks” and find it is that easy to enable anti-aliased since JDK 5. Just add a one-line code listed below at the very beginning of your whole application
System.setProperty("swing.aatext", "true");
That’s all
JFreeChart中的TimeSeries可能导致内存泄露
Nov 25th
前段时间说到现在的项目里在用JFreeChart。昨天晚上走之前没把客户端关掉,今天中午到公司发现程序已经崩了,狂抛OutOfMemoryError。用NB的profiler跟了一下,发现是JFreeChart或者说是没有正确使用JFreeChart的TimeSeries导致的后果
TimeSeries有一个方法setMaximumItemAge:
public void setMaximumItemAge(long periods)
该方法文档如下:
- Sets the number of time units in the ‘history’ for the series. This provides one mechanism for automatically dropping old data from the time series. For example, if a series contains daily data, you might set the history count to 30. Then, when you add a new data item, all data items more than 30 days older than the latest value are automatically dropped from the series.
- Parameters:
periods– the number of time periods.
maximumItemAge的默认值为Long.MAX_VALUE,因此如果不设置该值的话在可预见的未来过期数据将不会被丢弃,这样会导致TimeSeries的数据越来越大,尤其是在设置axis.setAutoRange(true);和axis.setFixedAutoRange(DATA_AGE);后(将横轴设为固定长度,图表只容纳限定数目个点,视觉上就是数据从右边“推入”图表,从左侧被“推出”)。虽然视觉上数据只有那么一点,但是从图表上消失的“旧”数据并没有从series里清除,导致最终的内存不足
未使用setMaximumItemAge的堆分布,才2分钟就开始深度GC,且堆大小已经开始扩大
未使用setMaximumItemAge的对象年龄(代),曲线很陡,说明很多对象没有被回收
使用setMaximumItemAge的堆分布,堆内存占用比较缓慢,堆大小未扩大,未进行深度GC
使用setMaximumItemAge的对象年龄(代),数值很高,是因为还没有进行深度GC的原因
在此提醒正在使用JFreeChart尤其是TimeSeries的给位,千万记得设置maximumItemAge
JFreeChart Developer Guide
Nov 15th
互联网很强大,Google很强大
JFreeChart是个很强大的Java作图库,真的很强大,强大得不看文档都不知道该怎么用……JFC虽然遵循LGPL但文档是收费的,个人版45刀一份。刚才google了一下,找到一本1.0.4的PDF(最新为1.0.11),直接挂这里有点嚣张,谁要的给我mail
更新:到这儿下载吧~~











