代码拉取完成,页面将自动刷新
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>
本链接池由济南汉驰信息科技有限公司编写本着开源原则欢迎探讨。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型