有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: 5e|yW0o
hj+iB,8
CountBean.java Mv_-JE9#>o
~/l5ys
/* eFXQ~~gOj
* CountData.java 4Gor*{
* ~9ynlVb7)r
* Created on 2007年1月1日, 下午4:44 \6L,jSoBl
* X')t6DQ( I
* To change this template, choose Tools | Options and locate the template under 155vY
* the Source Creation and Management node. Right-click the template and choose DNu-Ce%
* Open. You can then make changes to the template in the Source Editor. o8c5~fG1
*/ /{%p%Q[X
A(}D76o_
package com.tot.count; IlfH
9YEE.=]T
/** F9Co m}
*
AQm#a;
* @author cP2n,>:
*/ Cc}3@Nf{/
public class CountBean { #w1E3ahaX
private String countType; z{wZLqG
int countId; }/J<#}t
/** Creates a new instance of CountData */ GzEvp
public CountBean() {} @Pb%dS
public void setCountType(String countTypes){ `;HZO8
this.countType=countTypes; {'NXJ!I;t
} $i;m9_16
public void setCountId(int countIds){ \IX|{]*D
this.countId=countIds; v7b+
} lEXI<b'2
public String getCountType(){ 2e^6Od!Y?
return countType; 0@>
} JsK_q9]$e
public int getCountId(){ Ev]oPCeA
return countId; :3A^5}iz
} k<A|+![
} moCr4*jDX,
6(8zt"E
CountCache.java ZO8r8
[
'BX
U'
/* D $&6 8
* CountCache.java B+4WnR1%T
* )~be<G( a
* Created on 2007年1月1日, 下午5:01 $Y?[[>u
* .kc{)d*0K
* To change this template, choose Tools | Options and locate the template under 5b$QXO
* the Source Creation and Management node. Right-click the template and choose z`:tl7
* Open. You can then make changes to the template in the Source Editor. F~C7$
*/ 0lLg uBW@
Fp~0 ^
package com.tot.count; /WMJ#IE
import java.util.*; V\*J"ZP&
/** P X>>h}%
* ~9Cw5rwH<;
* @author 99*QfC
*/ -Ic<.ix
public class CountCache { -GZ:}<W6+
public static LinkedList list=new LinkedList(); zn#lFPj12
/** Creates a new instance of CountCache */ -'rb+<v
public CountCache() {} hh8U/dVk*
public static void add(CountBean cb){ Q5 =
if(cb!=null){ [PH56f
list.add(cb); "sJ@_lp
} }e-D&