有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下:
]ENK8bW
dw9T f ^V
CountBean.java WI&lj<*
gw+eM,Yp
/* gfN2/TDC]P
* CountData.java !zR)D|w&
* w#9_eq|3
* Created on 2007年1月1日, 下午4:44 n'M>xq_
* w"~<h;
* To change this template, choose Tools | Options and locate the template under \J3/keL
* the Source Creation and Management node. Right-click the template and choose _~&9*D$
{>
* Open. You can then make changes to the template in the Source Editor. DZk1ZLz
*/ lL0M^Nv
m(_9<bc>
package com.tot.count; Us=eq "eu
Vm,,uF
/** I3(d<+M
* !),t"Ae?>
* @author
oL-2qtv
*/ RgZOt[!.
public class CountBean { Hhl-E:"H`
private String countType; +D`*\d1
int countId; MA*
:<l
/** Creates a new instance of CountData */ -ihiG_f
public CountBean() {} .T8K-<R
public void setCountType(String countTypes){ N=~~EtX
this.countType=countTypes; 2+Yb
7 uI,
} e <"/'Ql!k
public void setCountId(int countIds){
)%F5t&lum
this.countId=countIds; 50$W0L$
} +
>nr.,qo3
public String getCountType(){ ~*-qX$gr
return countType; `5l01nOxJ
} U\vY/6;JI
public int getCountId(){ `
>U?v
return countId; cG_Vc[
} >{nH v)
} rt}^4IqL
v0LGdX)/Y
CountCache.java pr rT:Y
G3a7`CD
/* wxdyF&U
n
* CountCache.java 24B<[lSK
* iKAusWj
* Created on 2007年1月1日, 下午5:01 3i=Iu0
* `q_<Im%I
* To change this template, choose Tools | Options and locate the template under !Z|($21W
* the Source Creation and Management node. Right-click the template and choose o35fifM`
* Open. You can then make changes to the template in the Source Editor. 6Hf,6>
*/ ,b|-rU\
zk}{ dG^M:
package com.tot.count; L;/n!k.A
import java.util.*; G%:GeW
/** &