日期:2014-05-20  浏览次数:20627 次

请问一下此线程池为什么会死循环
需要完成的功能都可正常完成,
但是会出现死循环.
本线程池是通过状态的判断,来对XML进行生成的.
不知为何,劳烦各位.



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package xml.main;

import xml.bean.RequestBean;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import xml.common.ParentxmlHandler;
import xml.dao.XmlDao;

/**
 * 
 * @author Administrator
 */
public class xmlMultiThreadServer {
private ExecutorService executorService;// 线程池
private static List<Future> pageFutureList;
private final int POOL_SIZE_ONECPU = 10;// 单个CPU线程池大小
private int POOL_SIZE = 0;

public xmlMultiThreadServer() {
POOL_SIZE = Runtime.getRuntime().availableProcessors()
* POOL_SIZE_ONECPU;
pageFutureList = new ArrayList<Future>();
executorService = Executors.newCachedThreadPool();// 工厂类创建固定线程数(CPU核心数*每个U线程池大小)的线程池
System.out.println("startup StartWorkServer!");
}

public void service() {
List<RequestBean> list;
while (true) {
while (!hasFreeThread()) {
try {
Thread.sleep(2000);// 没有可用线程处理需等待2秒钟
} catch (InterruptedException e) {
e.printStackTrace();
}
}
int freeThreadNum = POOL_SIZE - pageFutureList.size();
XmlDao Dao = new XmlDao();
list = Dao.findAllIsNoOper(freeThreadNum);
System.out.println(list.size());
while (list.size() <= 0) {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
list = Dao.findAllIsNoOper(freeThreadNum);

}
for (RequestBean requestBean : list) {
ParentxmlHandler ParentxmlHandler = null;
Class<?> handler = null;
try {
XmlDao dao = new XmlDao();
String sendtype = dao.findsendtype();
if(sendtype.equals("1")){
handler = Class.forName("xml.handler.ExportSaleDataMainHandler");
}
if(sendtype.equals("2")){
handler = Class.forName("xml.handler.ExportSaleDataMonMainHandler");
}
if(sendtype.equals("3")){
handler = Class.forName("xml.handler.ExportKcDataMainHandler");
}
if(sendtype.equals("4")){
handler = Class.forName("xml.handler.ExportShopInfoHandler");
}
if(sendtype.equals("5")){
handler = Class.forName("xml.handler.ExportShopInfoHandler");
}
if(sendtype.equals("6")){
handler = Class.forName("xml.handler.ExportShopInfoHandler");
}
if(sendtype.equals("7")){
handler = Class.forName("xml.handler.ExportShopInfoHandler");
}
if(sendtype.equals("8")){
handler = Class.forName("xml.handler.ExportShopInfoHandler");
}
System.out.println("handler" + handler);
} catch (Exception e) {
e.printStackTrace();
}