有時要為每一篇文章統計其點擊次數
CountBean
/*
* CountData
*
* Created on
*
* To change this template
* the Source Creation and Management node
* Open
*/
package com
/**
*
* @author
*/
public class CountBean {
private String countType;
int countId;
/** Creates a new instance of CountData */
public CountBean() {}
public void setCountType(String countTypes){
this
}
public void setCountId(int countIds){
this
}
public String getCountType(){
return countType;
}
public int getCountId(){
return countId;
}
}
CountCache
/*
* CountCache
*
* Created on
*
* To change this template
* the Source Creation and Management node
* Open
*/
package com
import java
/**
*
* @author
*/
public class CountCache {
public static LinkedList list=new LinkedList();
/** Creates a new instance of CountCache */
public CountCache() {}
public static void add(CountBean cb){
if(cb!=null){
list
}
}
}
CountControl
/*
* CountThread
*
* Created on
*
* To change this template
* the Source Creation and Management node
* Open
*/
package com
import tot
import java
/**
*
* @author
*/
public class CountControl{
private static long lastExecuteTime=
private static long executeSep=
/** Creates a new instance of CountThread */
public CountControl() {}
public synchronized void executeUpdate(){
Connection conn=null;
PreparedStatement ps=null;
try{
conn = DBUtils
conn
ps=conn
for(int i=
CountBean cb=(CountBean)CountCache
CountCache
ps
ps
//ps
}
//int [] counts = ps
conn
}catch(Exception e){
e
} finally{
try{
if(ps!=null) {
ps
ps
ps=null;
}
}catch(SQLException e){}
DBUtils
}
}
public long getLast(){
return lastExecuteTime;
}
public void run(){
long now = System
if ((now
//System
//System
// System
lastExecuteTime=now;
executeUpdate();
}
else{
//System
}
}
}
//注
類寫好了
<%
CountBean cb=new CountBean();
cb
CountCache
out
CountControl c=new CountControl();
c
out
%>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20050.html