有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: u4SL:IH{D
LFHJj-nk
CountBean.java =_|G q|
ml1%C%
/* |M5#jVXj
* CountData.java [yQ%g;m
* lbIPtu
* Created on 2007年1月1日, 下午4:44 XJ3sqcS
* .|R4E
* To change this template, choose Tools | Options and locate the template under `{Q'iydU
* the Source Creation and Management node. Right-click the template and choose bK~Toz<k
* Open. You can then make changes to the template in the Source Editor. ^&1O:G*"
*/ &U|c=$!\
!vR Zh('R
package com.tot.count; &*+$38XE^
f?k0(rl
/** 2y^:T'p
* -2J37
* @author 0g|5s
*/ -#;xfJE
public class CountBean { Z*mbhod
private String countType; !.mR]El{K
int countId; 4l%W]'
/** Creates a new instance of CountData */ V27RK-.N!
public CountBean() {} S}%z0g<
public void setCountType(String countTypes){ +c<iVc|
this.countType=countTypes; r \ft{Z<P
} /ugyUpyg
public void setCountId(int countIds){ HFy9b|pjy
this.countId=countIds; 1r$-U h
} ,jis@]:
public String getCountType(){ wT":
return countType; ]Rxo}A
} X=]utn
public int getCountId(){ ~r8<|$;
return countId; fuUtM_11
} .4WJk>g
} #c@&mus
\uPzj_kU6
CountCache.java r@zT!.sc!
MukJ^h*V
/* _(h=@cv
* CountCache.java A[;deHg=
* MYy58N
* Created on 2007年1月1日, 下午5:01 JXU?'@QY
* YWH>tt9
* To change this template, choose Tools | Options and locate the template under =+j3E<w
* the Source Creation and Management node. Right-click the template and choose B1nm?E 0i
* Open. You can then make changes to the template in the Source Editor. 0!dNW,NfJ
*/ o6O-\d7^M
k"i3$^v8
package com.tot.count; BM /FOY;
import java.util.*; 8Zsaq1S
/** <5z!0m-G
* CipDeqau2
* @author ^*.$@M
*/ 23^>#b7st
public class CountCache { U; oXX
public static LinkedList list=new LinkedList(); "E2 0Y"[h
/** Creates a new instance of CountCache */ Q+
V<&
public CountCache() {} u)r/#fUZ
public static void add(CountBean cb){ BkXv4|UE
if(cb!=null){ xNOKa*
list.add(cb); .i4aM;Qy
} R~oJ-}iYX
} IXa~,a H71
} *2a" 2o
I&La0g