您的位置:首页 >> 编程开发 >> Java >> 线程 >> 正文
RSS
 

我的线程池代码

http://www.rdxx.com 02年10月15日 11:49 互联网 我要投稿

关键词: 线程池 , 代码 , 线程

      throw new JDOMException();
    }
  }

  public static ConsumeThreadPoolPara getConsumeThreadPoolPara(){
    if(consumeThreadPoolPara ==null){
      try {
        Element root = loadDocument();
        Element consumeThreadPool = root.getChild("ConsumeThreadPool");
        if (consumeThreadPool != null) { //代表有数据库配置
          consumeThreadPoolPara = new ConsumeThreadPoolPara();
          Element minPools = consumeThreadPool.getChild("minPools");
          consumeThreadPoolPara.setMinPools(Integer.parseInt(minPools.getTextTrim()));
          Element maxPools = consumeThreadPool.getChild("maxPools");
          consumeThreadPoolPara.setMaxPools(Integer.parseInt(maxPools.getTextTrim()));
          Element checkThreadPeriod = consumeThreadPool.getChild("checkThreadPeriod");
          consumeThreadPoolPara.setCheckThreadPeriod(Integer.parseInt(checkThreadPeriod.getTextTrim()));
        }
      }
      catch (JDOMException e) {
      }
    }
    return consumeThreadPoolPara;
  }
}

四、线程池源代码:
import java.util.*;

/**
 * <p>Title: 线程池</p>
 * <p>Description: 采集消费模块</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author 张荣斌
 * @version 1.0
 */

public class ThreadPool {
  private static int minPools = 10; //最小连接池数目
  private static int maxPools = 100; //最大连接池数目
  private static int checkThreadPeriod = 5; //检查连接池的周期
  ArrayList m_ThreadList;  //工作线程列表
  LinkedList m_RunList = null;  //工作任务列表
  int totalThread = 0;  //总线程数
  static int freeThreadCount = 0;  //未被使用的线程数目
  private java.util.Timer timer = null;  //定时器
  static Object o = new Object();

  static{  //先初始化线程池的参数
    ConsumeThreadPoolPara consumeThreadPoolPara = ParseConfig.getConsumeThreadPoolPara();
    if(consumeThreadPoolPara!=null){
      minPools = consumeThreadPoolPara.getMinPools();
      maxPools = consumeThreadPoolPara.getMaxPools();
      checkThreadPeriod = consumeThreadPoolPara.getCheckThreadPeriod()*60*1000;
    }
  }
  public void setMinPools(int minPools){
    this.minPools = minPools;

共6页  1 2 3 4 5 6

 
 
标签: 线程池 , 代码 , 线程 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站