用commons-net包写Ftp客户端下载(五)

这里我设置现成是20,然后出现了io异常,说socket无法读取。。而且FTPServer日志文件说,连接被关闭的错误。。

这个折磨的头大啊,死活找不出来原因。。。纠结纠结。。。。

于是上FtpServer的源码。。下载不多说。。和下载FtpServer一个页面里面。

用maven把项目导入Eclipse中,阅读。。。。

于是令人吐血的地方发现了。。。

package org.apache.ftpserver.impl中的DefaultFtpServerContext类中我发现了这么一些方法。。。。

  public synchronized ThreadPoolExecutor getThreadPoolExecutor() {
        if(threadPoolExecutor == null) {
            int maxThreads = connectionConfig.getMaxThreads();
            if(maxThreads < 1) {
                int maxLogins = connectionConfig.getMaxLogins();
                if(maxLogins > 0) {
                    maxThreads = maxLogins;
                }
                else {
                    maxThreads = 16;
                }
            }
            LOG.debug("Intializing shared thread pool executor with max threads of {}", maxThreads);
            threadPoolExecutor = new OrderedThreadPoolExecutor(maxThreads);
        }
        return threadPoolExecutor;
    }

然后connectionConfig里面我又看了下

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.ftpserver;

import org.apache.ftpserver.impl.DefaultConnectionConfig;

/**
 * Factory for creating connection configurations
 *
 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
 */
public class ConnectionConfigFactory {

    private int maxLogins = 10;

    private boolean anonymousLoginEnabled = true;

    private int maxAnonymousLogins = 10;

    private int maxLoginFailures = 3;

    private int loginFailureDelay = 500;

    private int maxThreads = 0;

    /**
     * Create a connection configuration instances based on the configuration on this factory
     * @return The {@link ConnectionConfig} instance
     */
    public ConnectionConfig createConnectionConfig() {
        return new DefaultConnectionConfig(anonymousLoginEnabled,
                loginFailureDelay, maxLogins, maxAnonymousLogins,
                maxLoginFailures, maxThreads);
    }

    /**
     * The delay in number of milliseconds between login failures. Important to 
     * make brute force attacks harder.
     * 
     * @return The delay time in milliseconds
     */
    public int getLoginFailureDelay() {
        return loginFailureDelay;
    }

    /**
     * The maximum number of anonymous logins the server would allow at any given time
     * @return The maximum number of anonymous logins
     */
    public int getMaxAnonymousLogins() {
        return maxAnonymousLogins;
    }

    /**
     * The maximum number of time an user can fail to login before getting disconnected
     * @return The maximum number of failure login attempts
     */
    public int getMaxLoginFailures() {
        return maxLoginFailures;
    }

    /**
     * The maximum number of concurrently logged in users
     * @return The maximum number of users
     */
    public int getMaxLogins() {
        return maxLogins;
    }

    /**
     * Is anonymous logins allowed at the server?
     * @return true if anonymous logins are enabled
     */
    public boolean isAnonymousLoginEnabled() {
        return anonymousLoginEnabled;
    }

    /**
     * Set she maximum number of concurrently logged in users
     * @param maxLogins The maximum number of users
     */

    public void setMaxLogins(final int maxLogins) {
        this.maxLogins = maxLogins;
    }

    /**
     * Returns the maximum number of threads the server is allowed to create for
     * processing client requests.
     * 
     * @return the maximum number of threads the server is allowed to create for
     *         processing client requests.
     */
    public int getMaxThreads() {
        return maxThreads;
    }

    /**
     * Sets the maximum number of threads the server is allowed to create for
     * processing client requests.
     * 
     * @param maxThreads
     *            the maximum number of threads the server is allowed to create
     *            for processing client requests.
     */
    public void setMaxThreads(int maxThreads) {
        this.maxThreads = maxThreads;
    }

    /**
     * Set if anonymous logins are allowed at the server
     * @param anonymousLoginEnabled true if anonymous logins should be enabled
     */
    public void setAnonymousLoginEnabled(final boolean anonymousLoginEnabled) {
        this.anonymousLoginEnabled = anonymousLoginEnabled;
    }

    /**
     * Sets the maximum number of anonymous logins the server would allow at any given time
     * @param maxAnonymousLogins The maximum number of anonymous logins
     */
    public void setMaxAnonymousLogins(final int maxAnonymousLogins) {
        this.maxAnonymousLogins = maxAnonymousLogins;
    }

    /**
     * Set the maximum number of time an user can fail to login before getting disconnected
     * @param maxLoginFailures The maximum number of failure login attempts
     */
    public void setMaxLoginFailures(final int maxLoginFailures) {
        this.maxLoginFailures = maxLoginFailures;
    }

    /**
     * Set the delay in number of milliseconds between login failures. Important to 
     * make brute force attacks harder.
     * 
     * @param loginFailureDelay The delay time in milliseconds
     */
    public void setLoginFailureDelay(final int loginFailureDelay) {
        this.loginFailureDelay = loginFailureDelay;
    }

}

我直接吐血了。。private int maxLogins = 10;。。。根据DefaultFtpServerContext,我发现了,FtpServer里面的

线程池默认值是10。。。也就是说FtpServer里面默认的线程池是10个线程。。。无语。。

难道apache就这么傻?答案是不能,所以我就找所有的配置文件,把用户的单个ip登录设置成1w,同时登录1w。。。

启动发现还是有问题。。。那怎么设置这个线程池。。。。

读源码把。。。。。

终于发现。。。在ftpd-typical.xml中

<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
	   http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd	
	   "
	id="myServer" max-logins="20000">
	<listeners>
		<nio-listener name="default" port="21">
		    <ssl>
                <keystore file="./res/ftpserver.jks" password="password" />
            </ssl>
		</nio-listener>
	</listeners>
	<file-user-manager file="./res/conf/users.properties" />
</server>


苍天,max-logins。。。。这里可以设置。。。。添加上之后,便可以变更线程池大小了。,。

于是,问题解决了。。。

 

对了,ftpserver目录/common/classes/下有log4j.properties。把info修改成debug启动。、。然后看log日志

 

[ INFO] 2011-10-20 18:48:14,234 [] [] Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7: display name [org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7]; startup date [Thu Oct 20 18:48:14 CST 2011]; root of context hierarchy [ INFO] 2011-10-20 18:48:14,288 [] [] Loading XML bean definitions from file [F:\developtool\ftpserver-1.0.6\apache-ftpserver-1.0.6\res\conf\ftpd-typical.xml] [DEBUG] 2011-10-20 18:48:14,300 [] [] Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl] [DEBUG] 2011-10-20 18:48:14,346 [] [] Loading schema mappings from [META-INF/spring.schemas] [DEBUG] 2011-10-20 18:48:14,350 [] [] Loaded schema mappings: {http://www.springframework.org/schema/lang/spring-lang.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd, http://www.springframework.org/schema/context/spring-context-2.5.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/context/spring-context.xsd=org/springframework/context/config/spring-context-2.5.xsd, http://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd, http://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd, http://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd, http://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd, http://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://mina.apache.org/ftpserver/ftpserver-1.0.xsd=org/apache/ftpserver/config/spring/ftpserver-1.0.xsd, http://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd, http://www.springframework.org/schema/jee/spring-jee-2.0.xsd=org/springframework/ejb/config/spring-jee-2.0.xsd, http://www.springframework.org/schema/jee/spring-jee-2.5.xsd=org/springframework/ejb/config/spring-jee-2.5.xsd, http://www.springframework.org/schema/lang/spring-lang-2.0.xsd=org/springframework/scripting/config/spring-lang-2.0.xsd, http://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd} [DEBUG] 2011-10-20 18:48:14,351 [] [] Found XML schema [http://mina.apache.org/ftpserver/ftpserver-1.0.xsd] in classpath: org/apache/ftpserver/config/spring/ftpserver-1.0.xsd [DEBUG] 2011-10-20 18:48:14,367 [] [] Found XML schema [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-2.5.xsd [DEBUG] 2011-10-20 18:48:14,397 [] [] Loading bean definitions [DEBUG] 2011-10-20 18:48:14,408 [] [] Loaded mappings [{http://www.springframework.org/schema/p=org.springframework.beans.factory.xml.SimplePropertyNamespaceHandler, http://www.springframework.org/schema/lang=org.springframework.scripting.config.LangNamespaceHandler, http://www.springframework.org/schema/jee=org.springframework.ejb.config.JeeNamespaceHandler, http://mina.apache.org/ftpserver/spring/v1=org.apache.ftpserver.config.spring.FtpServerNamespaceHandler, http://www.springframework.org/schema/util=org.springframework.beans.factory.xml.UtilNamespaceHandler, http://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler}] [DEBUG] 2011-10-20 18:48:14,427 [] [] Loading key store from "F:\developtool\ftpserver-1.0.6\apache-ftpserver-1.0.6\.\res\ftpserver.jks", using the key store type "jks" [DEBUG] 2011-10-20 18:48:14,427 [] [] Trying to load store from file [DEBUG] 2011-10-20 18:48:14,464 [] [] SSL configuration found for the listener, falling back for that for the data connection [DEBUG] 2011-10-20 18:48:14,486 [] [] Loaded 4 bean definitions from location pattern [res/conf/ftpd-typical.xml] [ INFO] 2011-10-20 18:48:14,486 [] [] Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7]: org.springframework.beans.factory.support.DefaultListableBeanFactory@641e9a [DEBUG] 2011-10-20 18:48:14,486 [] [] 4 beans defined in org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7: display name [org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7]; startup date [Thu Oct 20 18:48:14 CST 2011]; root of context hierarchy [DEBUG] 2011-10-20 18:48:14,497 [] [] Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@62937c] [DEBUG] 2011-10-20 18:48:14,498 [] [] Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@a31e1b] [ INFO] 2011-10-20 18:48:14,499 [] [] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@641e9a: defining beans [org.apache.ftpserver.listener.ListenerFactory#0,org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0,org.apache.ftpserver.FtpServerFactory#0,myServer]; root of factory hierarchy [DEBUG] 2011-10-20 18:48:14,500 [] [] Creating shared instance of singleton bean 'org.apache.ftpserver.listener.ListenerFactory#0' [DEBUG] 2011-10-20 18:48:14,500 [] [] Creating instance of bean 'org.apache.ftpserver.listener.ListenerFactory#0' [DEBUG] 2011-10-20 18:48:14,513 [] [] Eagerly caching bean 'org.apache.ftpserver.listener.ListenerFactory#0' to allow for resolving potential circular references [DEBUG] 2011-10-20 18:48:14,521 [] [] Finished creating instance of bean 'org.apache.ftpserver.listener.ListenerFactory#0' [DEBUG] 2011-10-20 18:48:14,521 [] [] Creating shared instance of singleton bean 'org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0' [DEBUG] 2011-10-20 18:48:14,522 [] [] Creating instance of bean 'org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0' [DEBUG] 2011-10-20 18:48:14,522 [] [] Eagerly caching bean 'org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0' to allow for resolving potential circular references [DEBUG] 2011-10-20 18:48:14,524 [] [] Finished creating instance of bean 'org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0' [DEBUG] 2011-10-20 18:48:14,524 [] [] Creating shared instance of singleton bean 'org.apache.ftpserver.FtpServerFactory#0' [DEBUG] 2011-10-20 18:48:14,524 [] [] Creating instance of bean 'org.apache.ftpserver.FtpServerFactory#0' [DEBUG] 2011-10-20 18:48:14,576 [] [] Eagerly caching bean 'org.apache.ftpserver.FtpServerFactory#0' to allow for resolving potential circular references [DEBUG] 2011-10-20 18:48:14,577 [] [] Creating instance of bean '(inner bean)' [DEBUG] 2011-10-20 18:48:14,578 [] [] Returning cached instance of singleton bean 'org.apache.ftpserver.listener.ListenerFactory#0' [DEBUG] 2011-10-20 18:48:14,580 [] [] Finished creating instance of bean '(inner bean)' [DEBUG] 2011-10-20 18:48:14,584 [] [] Creating instance of bean '(inner bean)#1' [DEBUG] 2011-10-20 18:48:14,584 [] [] Returning cached instance of singleton bean 'org.apache.ftpserver.usermanager.PropertiesUserManagerFactory#0' [DEBUG] 2011-10-20 18:48:14,584 [] [] File configured, will try loading [DEBUG] 2011-10-20 18:48:14,585 [] [] File found on file system [DEBUG] 2011-10-20 18:48:14,585 [] [] Finished creating instance of bean '(inner bean)#1' [DEBUG] 2011-10-20 18:48:14,585 [] [] Finished creating instance of bean 'org.apache.ftpserver.FtpServerFactory#0' [DEBUG] 2011-10-20 18:48:14,586 [] [] Creating shared instance of singleton bean 'myServer' [DEBUG] 2011-10-20 18:48:14,586 [] [] Creating instance of bean 'myServer' [DEBUG] 2011-10-20 18:48:14,586 [] [] Returning cached instance of singleton bean 'org.apache.ftpserver.FtpServerFactory#0' [DEBUG] 2011-10-20 18:48:14,587 [] [] Eagerly caching bean 'myServer' to allow for resolving potential circular references [DEBUG] 2011-10-20 18:48:14,587 [] [] Finished creating instance of bean 'myServer' [DEBUG] 2011-10-20 18:48:14,587 [] [] Publishing event in context [org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7: display name [org.springframework.context.support.FileSystemXmlApplicationContext@1ff5ea7]; startup date [Thu Oct 20 18:48:14 CST 2011]; root of context hierarchy] [DEBUG] 2011-10-20 18:48:14,587 [] [] Returning cached instance of singleton bean 'myServer' [DEBUG] 2011-10-20 18:48:14,664 [] [] Intializing shared thread pool executor with max threads of 20000 [ INFO] 2011-10-20 18:48:14,698 [] [] FTP server started

看到倒数第二条了吗? 线程池大小。。。。


于是到此结束。。。。



你可能感兴趣的:(多线程,ftpserver线程池)