package test; import org.apache.commons.pool.PoolableObjectFactory; import org.apache.commons.pool.impl.GenericObjectPool; import org.apache.log4j.Logger; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController; import com.gargoylesoftware.htmlunit.WebClient; //http://blog.csdn.net/m13321169565/article/details/8081410 public class PooledClientFactory{ private static Logger log = Logger.getLogger(PooledClientFactory.class); private final static PooledClientFactory instance =new PooledClientFactory(); //另外一种方案或许更为合适——对象池化技术。 //基于Apache的commons-pool池 private final GenericObjectPool clientPool =new GenericObjectPool(); public static PooledClientFactory getInstance() { return instance; } public PooledClientFactory(){ //实现对象池的对象创建工厂接口 clientPool.setFactory(new PoolableObjectFactory() { // 创建
Apache的commons-pool池创建多线程使用WebClient
本文详细介绍了如何在多线程环境中利用Apache Commons Pool库创建和管理WebClient,以实现高效的并发请求。通过实例代码,展示了如何配置池化策略,以及在实际应用中的最佳实践。
摘要由CSDN通过智能技术生成