0 Star 0 Fork 1

了了2014 / ftppool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

ftp连接池基于common-net 和 common-pool2

ftp连接池基于common-net 和 common-pool2

详细使用方法

依赖库

	<!-- ftpclient -->
       <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.6</version>
	</dependency>
		
	<dependency>
	    <groupId>org.apache.commons</groupId>
	    <artifactId>commons-pool2</artifactId>
	    <version>2.4.2</version>
	</dependency>

已经编译后的库

https://gitee.com/lliaoliao/ftppool/raw/master/bin/ftppool-1.0.jar

FTPPool 类里面有详细的调用情况

eg

public static void main(String[] args) throws Exception {
		FTPPoolConfig config = new FTPPoolConfig() ;
		config.setHost("192.168.1.20");
		config.setPort(21);
		config.setUsername("elen");
		config.setPassword("Elen@123");
		config.setPassiveMode("true");
		config.setClientTimeout(300000);
		config.setTransferFileType(2);
		//config.setMaxTotal(10);
		config.setMaxIdle(5);
		config.setMinIdle(1);
		config.setTestOnBorrow(true);
		config.setTestOnReturn(true);
		config.setTestWhileIdle(true);
		config.setNumTestsPerEvictionRun(10);
		config.setTimeBetweenEvictionRunsMillis(60000);
		
		FTPClientFactory f = new FTPClientFactory() ;
		f.setConfig(config);
	    final FTPPool pool = new FTPPool(config, f) ;
		for(int i = 20 ;i>0 ; i--){
			Thread t = new Thread(new Runnable() {
				
				@Override
				public void run() {
				   
					try {
						FTPClient ftp = pool.getPool().borrowObject() ;
						 System.out.println(Thread.currentThread().getName()+"--获得一个");
						Thread.sleep(60000);
						pool.getPool().returnObject(ftp);
						 System.out.println(Thread.currentThread().getName()+"取消一个");
					} catch (Exception e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					
				}
			},"name--"+i) ;
			t.start();
		}
	   
		
		System.out.println("执行完毕");
		
		Thread.sleep(60000*20);
	
		
	}

spring 调用方式

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans.xsd"
	default-autowire="byName">
	<bean id="ftpConfig" class="com.hatchsolution.ftp.pool.FTPPoolConfig" >
		<property name="host" value="192.168.1.20"/>
		<property name="port" value="21"/>
		<property name="username" value="elen"/>
		<property name="password" value="Elen@123"/>
		<property name="passiveMode" value="true"/>
		<property name="clientTimeout" value="300000"/>
		<property name="transferFileType" value="2"/>
		<property name="maxTotal" value="10"/>
		<property name="maxIdle" value="5"/>
		<property name="minIdle" value="2"/>
		<property name="testOnBorrow" value="true"/>
		<property name="testOnReturn" value="true"/>
		<property name="testWhileIdle" value="true"/>
		<property name="numTestsPerEvictionRun" value="10"/>
		<property name="timeBetweenEvictionRunsMillis" value="60000"/>
	</bean>	
	 
	<bean id="ftpClientFactory" class="com.hatchsolution.ftp.factory.FTPClientFactory" >
		<constructor-arg name="config" ref="ftpConfig"></constructor-arg>
	</bean>
	
	<bean id = "ftpPool" class="com.hatchsolution.ftp.pool.impl.FTPPool" scope="singleton">
		<constructor-arg name="factory" ref="ftpClientFactory"></constructor-arg>	
		
	</bean>
	
	<bean id = "ftpUtils" class="com.hatchsolution.ftp.FTPUtils" scope="singleton">
		<property name="pools" ref="ftpPool"/>
	</bean>
	
	
	
	
	
	
</beans>

本链接池由济南汉驰信息科技有限公司编写本着开源原则欢迎探讨。

空文件

简介

ftp连接池 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/lliaoliao/ftppool.git
git@gitee.com:lliaoliao/ftppool.git
lliaoliao
ftppool
ftppool
master

搜索帮助