有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: A&_i]o
8KdcLN@
CountBean.java d7-F&!sQ
aid)q&AcQ
/* G}hkr
* CountData.java B8#f^}8
* "F.J>QBd
* Created on 2007年1月1日, 下午4:44 O9 Au =
* ;uo|4?E:\(
* To change this template, choose Tools | Options and locate the template under $}h_EI6hS
* the Source Creation and Management node. Right-click the template and choose qpEC!~y
* Open. You can then make changes to the template in the Source Editor. MvjwP?J]
*/ r'JK$9
m5Laq'~0_
package com.tot.count; XuAc3~HAd
Yr(f iI
/** +WEO]q?K
* c.me1fGn
* @author ah@GSu;7
*/ U>M>FZ
public class CountBean { -3XnK5
private String countType; nh.v?|
int countId; c$Nl-?W
/** Creates a new instance of CountData */ 8w@jUGsc
public CountBean() {} ; >hPHx
public void setCountType(String countTypes){ >a]
s
this.countType=countTypes; H-y-7PW*~
} oO9iB:w
public void setCountId(int countIds){ Q ]koj!mMl
this.countId=countIds; U?m?8vhR6(
} _@3O`
public String getCountType(){ }j<_JI
return countType; #(}_2x5
} b:d.Lf{y7
public int getCountId(){ { dxyBDK
return countId; Hn2Q1lF-ip
} 9Qm{\
} '
xq5tRg>
cngPc]?N
CountCache.java K>p:?w
Fl(ZKpSZU
/* 5TW<1'u
* CountCache.java $G([#N<
* gmH0-W)=
* Created on 2007年1月1日, 下午5:01 HE.Dl7{
* Qz90 mb
* To change this template, choose Tools | Options and locate the template under
!{=%l+^.
* the Source Creation and Management node. Right-click the template and choose
rlh6\Fa
* Open. You can then make changes to the template in the Source Editor. g<jK^\eW
*/ -Y,Ibq
4'eVFu+62
package com.tot.count; 9 u89P
import java.util.*; k5\
zGsol
/** Iz=E8R g
* B'~i Z65
* @author :z5Ibas:
*/ =:}DD0o*
public class CountCache { +[nYu)puP
public static LinkedList list=new LinkedList(); CZno2$8@e
/** Creates a new instance of CountCache */ O*"wQ50Ou
public CountCache() {} %[F;TZt
public static void add(CountBean cb){ 6*oTT(0<p
if(cb!=null){ vb2O4%7tw
list.add(cb); |"&4"nwa
} Olrw>YbW
} ?fwr:aP~
} ~9 nrS9)
k5<