📄 threadpool.java
字号:
/*
* *****************************************************
* Copyright (c) 2005 IIM Lab. All Rights Reserved.
* Created by xuehao at 2005-10-12
* Contact: zxuehao@mail.ustc.edu.cn
* *****************************************************
*/
package org.indigo.spider;
import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
import EDU.oswego.cs.dl.util.concurrent.ThreadedExecutor;
import org.indigo.util.*;
/**
* 开源线程池的使用。
* @author wbz
*
*/
public class ThreadPool
{
private static ThreadPool itsPool=null;
private PooledExecutor itsPooledExecutor=null;
/**
* 构造函数,初始化线程池的一些参数。如线程池容量等。
*
*/
private ThreadPool()
{
itsPooledExecutor = new PooledExecutor();
itsPooledExecutor.setMinimumPoolSize( 1 );
String str = MainConfig.getInstance().getProperty("ThreadPoolSize");
if( str==null || str.equals("") )
str = "25";
int size=25;
size = Integer.parseInt( str );
itsPooledExecutor.setMaximumPoolSize( size );
itsPooledExecutor.waitWhenBlocked();
}
/**
* 单例模式实例化线程池对象。
* @return
*/
public static ThreadPool getInstance()
{
if( itsPool==null )
itsPool = new ThreadPool();
return itsPool;
}
/**
* 线程池执行的主要部分,线程池中的每个线程执行时都会调用此方法。
* @param obj 实现了Runnable接口的对象。
*/
public void execute( Runnable obj )
{
try
{
itsPooledExecutor.execute( obj );
} catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -