JAVA线程池
(1)根据xml文件来管理线程池的最大最小线程数
(2)对线程池通过Timer定期扫描以防止线程未激活;
(3)通过某一个变量(本程序中是freeThreadCount)来得到空闲线程的数目;
一、配置xml(listen.xml)是:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<ConsumeThreadPool>
<minPools>10</minPools> <!--线程池最小线程-->
<maxPools>100</maxPools> <!--线程池最大线程-->
<checkThreadPeriod>5</checkThreadPeriod> <!--检查线程池中线程的周期5分钟-->
</ConsumeThreadPool>
</config>
二、对于ConsumeThreadPoolPara的javabean:
import java.io.*;
public class ConsumeThreadPoolPara implements Serializable{
private int minPools;
private int maxPools;
private int checkThreadPeriod;
public int getMinPools(){
return minPools;
}
public int getMaxPools(){
return maxPools;
}
public int getCheckThreadPeriod(){
return checkThreadPeriod;
}
public void setMinPools(int minPools){
this.minPools = minPools;
}
public void setMaxPools(int maxPools){
this.maxPools = maxPools;
}
public void setCheckThreadPeriod(int checkThreadPeriod){
this.checkThreadPeriod = checkThreadPeriod;
}
public String toString(){
return minPools+" " + maxPools+" "+checkThreadPeriod;
}
public ConsumeThreadPoolPara() {
}
public static void main(String[] args) {
ConsumeThreadPoolPara consumeThreadPool1 = new ConsumeThreadPoolPara();
}
}
三、解析xml程序代码(生成ConsumeThreadPoolPara):
使用jdom解析:
import org.jdom.*;
import org.jdom.input.SAXBuilder;
import java.io.*;
import java.util.*;
public class ParseConfig {
static Hashtable Listens = null;
static ConnPara connpara = null;
static ConsumeThreadPoolPara consumeThreadPoolPara = null;
priva
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
最简单的服务器接受单用户请求的socket编程模型,代码写得不好,只是用来阐明意思
client side
import java.net.*;
import java.util.*;
import java.io.*;
public class Client {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
tr ......
第一,谈谈final, finally, finalize的区别。
final 修饰符(关键字)如果一个类被声明为final,意味着它不能再派生出新的子类,不能作为父类被继承。因此一个类不能既被声明为 abstract的,又被声明为final的。将变量或方法声明为final,可以保证它们在使用中不被改变。被声明为final的变量必须在声明时给定初值,而在以 ......