Search code examples
javaandroidperformanceftp-clientapache-commons-net

Apache Commons NET: Should I create a new FTPClient object on each connection or reuse one?


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?


Solution

  • 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.