java:FTP在多线程、多用户web应用程序中的应用
我正在使用SpringMVC开发一个应用程序。在业务流程中,将生成需要从应用程序服务器检索到web服务器的图像文件。我正在使用commons NetAPI以简单的方式完成它java:FTP在多线程、多用户web应用程序中的应用,java,multithreading,web-applications,static,ftp,Java,Multithreading,Web Applications,Static,Ftp,我正在使用SpringMVC开发一个应用程序。在业务流程中,将生成需要从应用程序服务器检索到web服务器的图像文件。我正在使用commons NetAPI以简单的方式完成它 public class FtpUtility{ private FTPClient ftpClient = new FTPClient(); public boolean retriveFileFromApp(String srcFile, String destFile){ boolean flag = fal
public class FtpUtility{
private FTPClient ftpClient = new FTPClient();
public boolean retriveFileFromApp(String srcFile, String destFile){
boolean flag = false;
try{
connectToFtp()
File dest = new File(destFile);
if(!dest.exists())
dest.mkdirs();
if(dest.exists())
dest.delete();
FileOutputStream destStream = new FileOutputStream(dest);
ftpClient.retrieveFile(srcFile, destStream);
}
catch(Exception e){
//exception handling
}
finally{
disconnect();
}
return flag;
}
private boolean connectToFtp(){
boolean flag = false;
try{
ftpClient.connect(appserverip); // connect to ftp
flag = ftpClient.login(ftpUserId, ftpPassword);
}
catch(Exception e){
//exception handling
}
return flag;
}
private void disconnect(){
try{
ftpClient.logout();
ftpClient.disconnect();
}
catch(Exception e){
//some exception handling
}
}
}
现在,当多个用户使用该应用程序时,他们同时使用该类的实例进行连接,然后断开连接。即使只有一个用户在为每次文件传输连接和断开连接
这是行不通的。FTP客户端是静态的,您可以连接它一次并通过同步连续使用它,或者是每个会话,每个会话同时创建、连接和使用它自己的客户端。您当前的两者混合使用无法工作。您正在连接ftp并断开连接。在这两个操作之间,您可以传递任意数量的文件。实际上,它在每个业务流程中都会生成一个条形码,并且该条形码会传输到web服务器以显示在网页上。一个业务流程不能传输多个文件对不起,我复制粘贴代码时没有删除静态文件。我在试那个东西。该问题现已编辑。