有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: VFmg"^k5
i,Wm{+H-O
CountBean.java K&IrTA
j}
jw(>@SXz
/* 26#Jhb E+
* CountData.java /.kna4k
* QJIItx4hE
* Created on 2007年1月1日, 下午4:44 y(3c{y@~X
* H;*a:tbxO+
* To change this template, choose Tools | Options and locate the template under h$7Fe +#I#
* the Source Creation and Management node. Right-click the template and choose q?-3^z%u
* Open. You can then make changes to the template in the Source Editor. ncJFB,4
*/ feI[M;7u
Z~phOv
package com.tot.count; FO(0D?PCR
%6IlE.*,
/** 7l#2,d4
*
&QOWW}
* @author *&dW\fx
*/ )y/DGSd
public class CountBean { f{^M.G@
private String countType; k#Ez
int countId; <K#'3&*$s
/** Creates a new instance of CountData */ (4/]dTb
public CountBean() {} W93JY0Ls9|
public void setCountType(String countTypes){ &I}T<v{f
this.countType=countTypes; Q),3&4pM
} NB
W%.z
public void setCountId(int countIds){ [cQ<dVaTX
this.countId=countIds; B=gsd0^]
} |j~EV~AJ
public String getCountType(){ UrhM)h?%
return countType; Z'}(t,
} Vy%
:\p+
public int getCountId(){ wsJ%*
eYf
return countId; U!\2K~
} Dz8:;$/
} [UJEU~XC
TXJY2J*24
CountCache.java c.8((h/
iIGI=EwZ
/* A`x
-L
* CountCache.java iJZ|[jEDV
* JIP+ !2
* Created on 2007年1月1日, 下午5:01 lLkmcHu
* ||=[kjG~
* To change this template, choose Tools | Options and locate the template under zD)IU_GWa
* the Source Creation and Management node. Right-click the template and choose 6@?aVM~
* Open. You can then make changes to the template in the Source Editor. ovDJ{3L6O
*/ t8DL9RW'
&>W (l.
package com.tot.count; fKTDt%
import java.util.*; i+)}aA
/** 9QH9gdiw
* 0eqi1;$b]
* @author xBL$]>
*/ b'7z DZI]
public class CountCache { |k`f/*
public static LinkedList list=new LinkedList(); Z&dr0w8
/** Creates a new instance of CountCache */ \o:ELa HY
public CountCache() {} ]{,Gf2v;;d
public static void add(CountBean cb){ *^@#X-NG
if(cb!=null){ 2&