| CountBean cb=(CountBean)CountCache.list.getFirst(); CountCache.list.removeFirst(); ps.setInt(1, cb.getCountId()); ps.executeUpdate();⑴ //ps.addBatch();⑵ } //int [] counts = ps.executeBatch();⑶ conn.commit(); }catch(Exception e){ e.printStackTrace(); } finally{ try{ if(ps!=null) { ps.clearParameters(); ps.close(); ps=null; } }catch(SQLException e){} DBUtils.closeConnection(conn); } } public long getLast(){ return lastExecuteTime; } public void run(){ long now = System.currentTimeMillis(); if ((now - lastExecuteTime) > executeSep) { //System.out.print("lastExecuteTime:" lastExecuteTime); //System.out.print(" now:" now "n"); // System.out.print(" sep=" (now - lastExecuteTime) "n"); lastExecuteTime=now; executeUpdate(); } else{ //System.out.print("wait for " (now - lastExecuteTime) " seconds:" "n"); } } } //注:假如你的数据库驱动支持批处理,那么可以将⑵,⑶标记的代码前的注释去掉,同时在代码⑴前加上注释 类写好了,下面是在JSP中如下调用。 <% CountBean cb=new CountBean(); cb.setCountId(Integer.parseInt(request.getParameter("cid"))); CountCache.add(cb); out.print(CountCache.list.size() "<br>"); CountControl c=new CountControl(); c.run(); out.print(CountCache.list.size() "<br>"); %>
|
| 共2页: 上一页 [1] 2 下一页 |
评论加载中…