📄 blacklistcheck.java
字号:
package com.wayout.wayoutsp.publics;import java.sql.*;import java.util.Calendar;import java.util.Hashtable;/** * <p>Title: </p> * <p>Description: 短信平台</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: wayout</p> * @author wayout * @version 1.0 */public class BlackListCheck extends Thread { private volatile PreparedStatement getBlackNumPstmt = null; private static BlackListCheck blackListCheck=null; private static Hashtable blackHashTable=null; private final static String SQLgetBlackNum="select distinct(black_num) from t_black_num_list where state=0"; private BlackListCheck() { blackHashTable=new Hashtable(); listBlack(); }//取得启动对象 public static BlackListCheck getInstance(){ if(blackListCheck==null){ blackListCheck=new BlackListCheck(); return blackListCheck; } return blackListCheck; } //检测是否存在此用户 true:在黑名单中 false:不在黑名单中public boolean ifExistUser(String[] userNumber){ try{ for(int i=0;i<userNumber.length;i++){ if(blackHashTable.containsKey(userNumber[i])){ //System.out.println("get one black user: "+userNumber[i]) ; PublicConstants.writeLog.info("BlackListCheck::ifExistUser::get one black user: "+userNumber[i],1); return true; } } }catch(Exception e){ return false; } return false; } public void run() { com.wayout.wayoutsp.publics.PublicFuction.threadSleep(6000); while(true) { while(!listBlack()){ PublicConstants.writeLog.info("BlackListCheck::run()::get black number list error!!!",0); System.out.print("BlackListCheck::run()1::get black number list error!!!") ; com.wayout.wayoutsp.publics.PublicFuction.threadSleep(1000*60); } com.wayout.wayoutsp.publics.PublicFuction.threadSleep(1000*60*10); //System.out.println("get black number list once!!!") ; PublicConstants.writeLog.info("BlackListCheck::run()::get black number list once!!!",0); } }//将黑号码读入内存 private boolean listBlack(){ try{ Connection conn=DatabaseAccess.connectDatabase( PublicConstants.CONNECTION_URL,PublicConstants.DB_USER,PublicConstants.DB_PASS); getBlackNumPstmt=conn.prepareStatement(SQLgetBlackNum); ResultSet rst=getBlackNumPstmt.executeQuery(); blackHashTable.clear(); int i=0; while(rst.next()){ blackHashTable.put(rst.getString(1).trim(),"aa"); i++; } PublicConstants.writeLog.info("BlackListCheck::listBlack::get black number list count: "+i,2); //System.out.println("get black number list count: "+i) ; conn.close() ; return true; }catch(Exception e){ System.out.println("listBlack() error: "+e); } return false; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -