有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: YMVmpcz
Tj}%G
CountBean.java R ^ZOcONd-
#Z,@yJ2wl
/* ibLx'<
* CountData.java K+~1z>&
* @>&b&uj7T
* Created on 2007年1月1日, 下午4:44 L`(\ud
* v`S ;.iD
* To change this template, choose Tools | Options and locate the template under G cB<i
* the Source Creation and Management node. Right-click the template and choose (M<l}pl)
* Open. You can then make changes to the template in the Source Editor. z]D/Qr
*/ MI-S}Qoe
uN1VkmtDO
package com.tot.count; '}:(y$9.`
KD]`pqN9
/** {`-AIlH(
* X ka+1c
* @author n5)ml)m
*/ 8l'W[6
public class CountBean { ZXXJ!9-&+J
private String countType; }R%*J
int countId; M+%qVwp
/** Creates a new instance of CountData */ KT+{-"4-
public CountBean() {} CHq5KB98+
public void setCountType(String countTypes){ ym_as8A*Q
this.countType=countTypes; R / ND f`
} ] ^?w0A
public void setCountId(int countIds){ )l/
.<`|
this.countId=countIds; <H{K&,Z(ZM
} lr?SL\D
public String getCountType(){ %dzO*/8cWo
return countType; mwsdl^c
} 5z2("[8L&
public int getCountId(){ hwA&SS
return countId; /t! 5||G
} qz2`%8}F)
} %I{>H%CjE
pvb&vtp
CountCache.java (nXnP{yb
g4YlG"O[~
/* #)@#Qd
* CountCache.java o7WAH@g
* 1Kr$JIcd
* Created on 2007年1月1日, 下午5:01 4jGN:*kZ
* f=VlO d
* To change this template, choose Tools | Options and locate the template under !YI<A\P
* the Source Creation and Management node. Right-click the template and choose ]mz '(t
* Open. You can then make changes to the template in the Source Editor. NHe)$%a=H
*/ FP}I+Ys
iOSt=-p
package com.tot.count; <&g