有时要为每一篇文章统计其点击次数,如果每一次浏览都要更新一次库的话,那性能在访问量很大的情况下,服务器的压力就会很大了,比较好一点的方法就是先将要更新的数据缓存起来,然后每隔一段时间再利用数据库的批量处理,批量更新库。源码如下: #4<=Ira5
RAWzQE}
CountBean.java yhrjML2K
WyRSy-{U(}
/* @saK:z
* CountData.java QseV\; z
* sDAP'&
* Created on 2007年1月1日, 下午4:44 =J|jCK[r
* ,&y_^-|d
* To change this template, choose Tools | Options and locate the template under _D$1CaAYo
* the Source Creation and Management node. Right-click the template and choose e=3C*+lq\
* Open. You can then make changes to the template in the Source Editor. W]XM<# ^^
*/ ,4Q8r:_ u
suE8"v!sk
package com.tot.count; Kp^"<%RT
F{^\vFp
/** <@[;IX`YN
* bR,Es~n
* @author cQ'x]u_
*/ ug.|ag'R
public class CountBean { }ice*3'3
private String countType; vG7Mk8mIr
int countId; L9XfR$7,z
/** Creates a new instance of CountData */ &nwS7n1eb
public CountBean() {} QUaV;6
4
public void setCountType(String countTypes){ h(R7y@mp\0
this.countType=countTypes; -%|
]
d ;
} }a#T\6rY
public void setCountId(int countIds){ #-PMREgO
this.countId=countIds; <$K=3&:s8q
} QT
zN
public String getCountType(){ k`&FyN^)
return countType; T+aNX/c|>
} -agB ]j
public int getCountId(){ :y`LF<
return countId; O2?yI8|Jn
} SP/b4
} 8EMBqhl
~(-1mB,
CountCache.java {to(?`Y
l1|*(%p?X
/* YtKT3u:x
* CountCache.java o5 ~VT!'[
* +H?g9v40
* Created on 2007年1月1日, 下午5:01 [s`B0V`04
* I\1"E y
* To change this template, choose Tools | Options and locate the template under 2wnk~URj
* the Source Creation and Management node. Right-click the template and choose \!30t1EZ
* Open. You can then make changes to the template in the Source Editor. n#Dy
YVb
*/ 0Ze&GK'Hf
]
Ok &%-
package com.tot.count; >~Gy+-
import java.util.*; lR7;{zlSf'
/** jA;b2A]G
* kTfRm^
* @author {D^
)%{
*/ a%BC{XX
public class CountCache { !vRN'/(Vyu
public static LinkedList list=new LinkedList(); f*rub. y
/** Creates a new instance of CountCache */ Q]GS#n
public CountCache() {} A'7Y{oPHX
public static void add(CountBean cb){ %'h:G
Bkd
if(cb!=null){ j^8HTa0Cy|
list.add(cb); l3BN,HNv+
} ;<[!;8
} CQ<