//代碼段1
多線程
int threadNumber;
int everySize = 100;this
int beginIndex = 0;
if(ruleList != null && ruleList.size() >0){
threadNumber = (ruleList.size()-1)/everySize + 1;
beginIndex = everySize * i;spa
//根據線程數,循環建立線程
for(int i = 0 ; i < threadNumber ; i++){
if(i == threadNumber-1){
everySize = ruleList.size() - everySize*i;
}
Multithreading multithreading = new Multithreading(ruleList, everySize,beginIndex);
Thread thread = new Thread(multithreading);
thread.start();
}
}.net
//代碼段2 多線程類線程
/**
* 建立一個多線程的類
* @author jade
* @Date 2015/3/23
*/
class Multithreading implements Runnable{
List<OriginBasicRuleVO> list = new ArrayList<OriginBasicRuleVO>();
//int threadNum; //線程數:設置個默認值是5,在此處好像沒用
int everySize; //循環的次數
int beginIndex; //每次循環的開始位置
/**
* 使用構造方法來傳遞值
* @param alist
* @param threadNum
* @param everySize
*/
public Multithreading(List<OriginBasicRuleVO> alist,int everySize,int beginIndex){
this.list.addAll(alist);
this.everySize = everySize;jade
this.beginIndex = beginIndex;
}
public void run() {
OriginInfoOperation origin = new OriginInfoOperation();
for(int i= beginIndex; i < everySize+beginIndex; i++){
origin.querySolrToOrigin(list.get(i));
}
}
}get