?? 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 + -