为什么我的Java代码在使用SmbFileInputStream和BufferedOutputStream时陷入无限循环

问题描述 投票:0回答:1

我有一个Java代码,它是由我之前的某个人编写的。该代码在AIX中运行良好,但是最近我们不得不将所有脚本从AIX移到RHEL 7.6。在RHEL上,代码似乎陷入了一个漫长的循环,而完成该过程大约需要5分钟的时间仅花费数小时。

循环使用SmbFileInputStream和BufferedOutputStream。日志不显示任何错误/异常。

任何帮助都会受到高度赞赏,因为AIX服务器将在下周停用,我需要使其在RHEL上正常工作。

public File getSMBFile(SmbFile infile, String username, String password, String localdir) throws Exception {

    SmbFileInputStream smbIn = new SmbFileInputStream(infile);
    //File temp = File.createTempFile(infile.getName(), null);
    //temp.deleteOnExit();

    File localFile = new File(localdir, infile.getName());
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(localFile));

    byte[] b = new byte[8192];
    int n = 0;

    while ((n = smbIn.read(b)) > 0) {
        log.info("In while" + localFile + " to " + b + " " + 0 + " " + n);
        out.write(b, 0, n);
    }

    out.flush();
    out.close();

    smbIn.close();
    out.close();
    log.info("LocalFile " + localFile);
    return localFile;
}

此循环是代码进入无限循环并持续运行数小时的地方:

while ((n = smbIn.read(b)) > 0) {
    log.info("In while" + localFile + " to " + b + " " + 0 + " " + n);
    out.write(b, 0, n);
}

日志输出:2019年12月30日10:16:18 com.perceptionit.configuration.inventory.processing.FileCollector getSMBFile信息:在while / opt / dataloading / data / statisticalbss / 4G_Updated_Region-Sheet-15-11-2019.xlsx到[B @ fc12260b 0 81922019年12月30日10:17:18 com.perceptionit.configuration.inventory.processing.FileCollector getSMBFile信息:在while / opt / dataloading / data / statisticalbss / 4G_Updated_Region-Sheet-15-11-2019.xlsx到[B @ fc12260b 0 81922019年12月30日10:18:18 com.perceptionit.configuration.inventory.processing.FileCollector getSMBFile信息:在while / opt / dataloading / data / statisticalbss / 4G_Updated_Region-Sheet-15-11-2019.xlsx到[B @ fc12260b 0 8192

java rhel7
1个回答
0
投票

在该代码段中没有什么可以进入无限循环的。在最坏的情况下,while循环将一次读取one byte并最终退出循环。

查看您的日志,显然不是这样。它读取8192个字节(提供的字节数组的大小),但是读取8192个字节的时间却很长,只有一分钟:10:17:18 PM-10:16:18 PM

我在Google上搜索了SmbFileInputStream wait too long on RHEL,此答案显示了第一个:JCIFS: file retrieval is too slow to be usable

对于如何深入研究和解决此问题,有很多选择。

© www.soinside.com 2019 - 2024. All rights reserved.