java分組批量執行,發短信、創建Lucene索引(應用場景)

//新聞總數
public void method(){
				int countNum = LuceneService.getMyLuceneInformationsCount(null);
//				int count = 100;
				int groupNum = 1000;//一組1000條
				int group = 0;
				if(countNum%groupNum == 0){
					group = countNum/groupNum;
				}else{
					group = countNum/groupNum+1;
				}
				for(int a = 1;a<=group;a++){
					System.out.println(a+"-----------"+group);
					createIndex((a-1)*groupNum,groupNum,conn);
				}
}

 //分組創建索引
	private void createIndex(int start,int limit,Connection conn){
    	<span style="white-space:pre">	</span>List<Information> infor = getInforList(start,limit,conn);
		LuceneInformation.creteIndex(infor,INDEXPATH_Information);
    }
	//新聞查詢
	public static List<Information>  getInforList(int start,int limit,Connection conn){
		List<Information> list = new ArrayList<Information>();
		Statement st = null;
		ResultSet rs = null;
		try {
			st = conn.createStatement();
			String sql = "select id,blRecommend,dtCreate,lngReadNum,strOrganName,version" +
					",strPID,strInfoID,strInfoTitle,strInfoContent,strCreate,blDeleteState,blPass  from information limit "+start+","+limit+"";
			rs = st.executeQuery(sql); 
			while (rs.next()) {
				Information info = new Information();
				info.setId(rs.getLong("id"));
				info.setStrRecomState(rs.getString("blRecommend"));
				info.setDtCreate(rs.getTimestamp("dtCreate"));
				info.setLngReadNum(rs.getLong("lngReadNum"));
				info.setStrOrgan(rs.getString("strOrganName"));
				info.setVersion(rs.getInt("version"));
				info.setStrPID(rs.getLong("strPID"));
				info.setStrInfoID(rs.getString("strInfoID"));
				info.setStrInfoTitle(rs.getString("strInfoTitle"));
				info.setStrInfoContent(rs.getString("strInfoContent"));
				info.setFirst_name(rs.getString("strCreate"));
				info.setBlDeleteState(rs.getBoolean("blDeleteState"));
				info.setBlPass(rs.getBoolean("blPass"));
				list.add(info);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(st != null){
				try {
					st.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(rs != null){
				try {
					rs.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		return list;
	}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章