If you can switch to SFTP, the Jsch library supports opening multiple channels over a single physical connection.
Otherwise you could implement a pool of FTP clients and block the consumer if there are no clients available. When a consumer completes its operation, return the client to the pool and wake up any waiting threads. A simple BlockingQueue
is likely all you would need.
Most servers will time out idle connections, though, so you'd have to deal with a broken connection when getting one from the pool.
Finally, if you use Spring Integration instead of rolling your own, the FTP outbound channel adapter can be configured to use a CachingSessionFactory
, which handles the pooling for you.