Java SmbFile检查Samba目录是否存在()需要很长时间

时间:2015-10-20 12:15:06

标签: java performance samba file-exists

我有一段代码将Java中的文件写入虚拟服务器上的共享Samba文件夹,但我遇到了性能问题。

我的代码所做的第一件事就是检查Samba文件夹是否存在。如果是,它会实例化它要写的文件。然后发生更多无关紧要的事情。

如果我查看我的日志文件,Instantiated destination samba directory...Checking if the file already exists...之间总是有6秒钟。这意味着if(!destination.exists)需要6秒,看起来非常长,因为if(smbOutputFile.exists))甚至不需要1秒。 (在我的测试用例中,它们都存在)。

这个性能问题可能是什么因素?有没有办法加快这个速度?

SmbFile destinationShare = new SmbFile(sambaDestinationPath, destinationAuthentication);
logger.info("Instantiated destination samba directory : " + destinationShare);

if (!destinationShare.exists()) { //destinationShare = a directory 
    destinationShare.mkdir();
    logger.debug("Shared directory created");
}

smbOutputFile = new SmbFile(sambaDestinationPath + filename, destinationAuthentication);

logger.debug("Checking if the file already exists and rename it to '.old'");
if (smbOutputFile.exists()) { //smbOutputFile = a file 
    //Do something 
}

谢谢!

0 个答案:

没有答案
相关问题