📄 persistentfreecustomer.java
字号:
package com.wireless.sms.gwif.smsagent.func;
import java.util.*;
import java.sql.*;
import org.apache.log4j.Logger;
import com.wireless.sms.pub.db.ConnectionPool;
import com.wireless.sms.gwif.smsagent.global.*;
public class PersistentFreeCustomer {
private static ConnectionPool pool = ConnectionPool.getInstance();
private static HashMap map = new HashMap();
private static Logger mtlog = LoggerConstant.mt_log;
static{
initReloadData();
}
private static void initReloadData(){
mtlog.info("Init reload data ...");
Timer timer = new Timer(true);
timer.schedule( new TimerTask(){
public void run(){
mtlog.info("Reload free user datas ...");
if( map.size() == 0 ){
mtlog.info("map.size == 0");
return;
}
else{
mtlog.info("map.size != 0");
}
HashMap tmpMap = new HashMap();
Iterator ite = map.keySet().iterator();
while (ite.hasNext()) {
String gatewayID = (String)ite.next();
Vector result = reloadData(gatewayID);
if (result != null) {
tmpMap.put(gatewayID, result);
}
}
map = tmpMap;
}
}, 5, 300000);
}
private synchronized static Vector reloadData(final String gatewayID){
Vector result = null;
Connection conn = null;
Statement stmt = null;
try {
conn = pool.getConnection();
stmt = conn.createStatement();
String sql = "select * from smsplatform.sms_subuser t " +
"where t.datcurtcustom > sysdate - 3 " +
"and t.vc2isactive = '1' " +
"and t.numgatewayid = " + gatewayID;
mtlog.info("sql : " + sql);
ResultSet rs = stmt.executeQuery(sql);
result = new Vector();
while (rs.next()) {
String tmp = rs.getString("numsrvid") + "-" + rs.getString("vc2feetermid");
result.add(tmp);
mtlog.info("read data : " + tmp);
}
} catch (Exception e) {
mtlog.error(e.getMessage());
return null;
}
finally{
try{
if (conn != null) {
conn.close();
}
if (stmt != null){
stmt.close();
}
}catch(Exception e){
mtlog.info("数据库关闭异常 : " + e.getMessage());
}
}
return result;
}
public static boolean contains(String gatewayID, String serviceID, String feeTermID){
Vector result = null;
if( !map.containsKey(gatewayID) ){
result = reloadData(gatewayID);
if( result != null ){
map.put(gatewayID, result);
}
}
else{
result = (Vector)map.get(gatewayID);
}
if( result != null && !result.contains(serviceID + "-" + feeTermID) ){
return false;
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -