Apache的百科全书网:我应该创建每个连接上一个新的FtpClient的对象或重用呢? [英] Apache Commons NET: Should I create a new FTPClient object on each connection or reuse one?

查看:409
本文介绍了Apache的百科全书网:我应该创建每个连接上一个新的FtpClient的对象或重用呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道:在我的Java应用程序,每一个我需要连接到FTP服务器时,我应该创建一个新的FtpClient的对象,或者我应该创建一个FtpClient的()对象,并重复使用,每次我连接到FTP服务器?

I'm just wondering: in my Java application, each time I need to connect to an FTP server, should I create a new FTPClient object, or should I create one FTPClient() object and re-use that each time I connect to an FTP server?

推荐答案

重新使用效果会更好,因为你要创建一个新的连接,每次不会需要一个新的实例,甚至到新的服务器。由于连接和断开连接方法可以做的工作给你。

Reusing would be better since you wont need a new instance every time you are creating a new connection, even to a new server. Because the connect and disconnect methods can do the job for you.

所以重用尽可能多的对象,你可以。

So reuse as many objects as you can.

这篇关于Apache的百科全书网:我应该创建每个连接上一个新的FtpClient的对象或重用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆