Java服务器端Socket线程池计算机等级考试

文章作者 100test 发表时间 2009:07:16 19:09:33
来源 100Test.Com百考试题网


  编辑特别推荐:

  全国计算机等级考试(等考)指定教材

  全国计算机等级考试学习视频

  全国计算机等级考试网上辅导招生

  全国计算机等级考试时间及科目预告

  百考试题教育全国计算机等级考试在线测试平台

  全国计算机等级考试资料下载

  全国计算机等级考试论坛

  import java.util.Vector.
  import java.net.*.
  import java.io.*.
  public class ThreadPool {
  public static final int MAX_THREADS = 100.
  public static final int MAX_SPARE_THREADS = 50.
  public static final int MIN_SPARE_THREADS = 10.
  public static final int WORK_WAIT_TIMEOUT = 60 * 1000.
  protected Vector pool. //存放空闲线程
  protected MonitorRunnable monitor. //A monitor thread that monitors the pool for idel threads.
  protected int maxThreads. //Max number of threads that you can open in the pool.
  protected int minSpareThreads. //Min number of idel threads that you can leave in the pool.
  protected int maxSpareThreads. //Max number of idel threads that you can leave in the pool.
  protected int currentThreadCount. //Number of threads in the pool.
  protected int currentThreadsBusy. //Number of busy threads in the pool.
  protected boolean stopThePool. //Flag that the pool should terminate all the threads and stop.
  /**
  * Construct
  */
  public ThreadPool() {
  maxThreads = MAX_THREADS.
  maxSpareThreads = MAX_SPARE_THREADS.
  minSpareThreads = MIN_SPARE_THREADS.
  currentThreadCount = 0.
  currentThreadsBusy = 0.
  stopThePool = false.
  }
  /**
  * 启动线程池
  */
  public synchronized void start() {
  adjustLimits(). //调整最大和最小线程数及最大和最小多余线程数.
  openThreads(minSpareThreads). //打开初始线程
  monitor = new MonitorRunnable(this). //Runnable对象实例 //A monitor thread that monitors the pool for idel threads.
  }
  public void setMaxThreads(int maxThreads) {
  this.maxThreads = maxThreads.
  }
  public int getMaxThreads() {
  return maxThreads.
  }
  public void setMinSpareThreads(int minSpareThreads) {
  this.minSpareThreads = minSpareThreads.
  }
  public int getMinSpareThreads() {
  return minSpareThreads.
  }
  public void setMaxSpareThreads(int maxSpareThreads) {
  this.maxSpareThreads = maxSpareThreads.
  }
  public int getMaxSpareThreads() {
  return maxSpareThreads.
  }
  /**
  * 线程池管理方法.
  * 当空闲队列线程中没有空闲线程时,则增加处理(空闲)线程数量.
  * 如果线程数量已达到最大线程数,则新的连接进行等待.
  * 当请求到来,且有空闲线程时调用处理线程进行具体业务处理.
  * @param r ThreadPoolRunnable
  */

相关文章


JBoss集群配置前言与集群知识计算机等级考试
JBoss集群配置代码实例计算机等级考试
JBoss集群中建立JMS集群服务计算机等级考试
浅析JBoss控制台密码的设置计算机等级考试
Java服务器端Socket线程池计算机等级考试
JS及J2EE开发中解决乱码的小方法计算机等级考试
澳大利亚华人论坛
考好网
日本华人论坛
华人移民留学论坛
英国华人论坛