性能:使用JCIF将文件复制到Windows网络的速度非常慢 [英] Performance: Very slow file copying to Windows network using JCIF

查看:310
本文介绍了性能:使用JCIF将文件复制到Windows网络的速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从本地计算机复制到Windows服务器中的共享"文件夹.这是我使用的功能.

public static void copyFileUsingJcifs(final String domain, final String userName, final String password, final String sourcePath, final String destinationPath) throws IOException {
    final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, userName, password);
    final SmbFile sFile = new SmbFile(destinationPath, auth);
    final SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(sFile);
    final FileInputStream fileInputStream = new FileInputStream(new File(
            sourcePath));

    final byte[] buf = new byte[16384];
    int len;
    while ((len = fileInputStream.read(buf)) > 0) {
        smbFileOutputStream.write(buf, 0, len);
    }
    fileInputStream.close();
    smbFileOutputStream.close();
}

我尝试了答案,但是没有不为我工作.当我进行普通复制(复制和粘贴)时,一个25MB的文件最多只需要 8分钟.但是,当我使用带有此功能的java程序时,它花费的时间超过 20分钟.如何使复制速度更快? 预先感谢.

解决方案

我注意到,jCIFS对读取的每个块都执行了操作"(afair jcifs.smb.SmbTransport.checkStatus(..)),即每个读入缓冲区的块.这意味着增加缓冲区的大小实际上可能会加快速度,尽管实际的问题仍然存在,但只会发生1到2次,对整体时间的影响较小.

设置"jcifs.util.loglevel = 3"并查看真正的错误是很有帮助的.

在我的情况下,我不得不最后设置"jcifs.smb.client.dfs.disabled = false",因为"jcifs.resolveOrder = DNS"无济于事..

I'm trying to copy a file from my local machine to Shared folder in a windows server. This is the function which I used.

public static void copyFileUsingJcifs(final String domain, final String userName, final String password, final String sourcePath, final String destinationPath) throws IOException {
    final NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, userName, password);
    final SmbFile sFile = new SmbFile(destinationPath, auth);
    final SmbFileOutputStream smbFileOutputStream = new SmbFileOutputStream(sFile);
    final FileInputStream fileInputStream = new FileInputStream(new File(
            sourcePath));

    final byte[] buf = new byte[16384];
    int len;
    while ((len = fileInputStream.read(buf)) > 0) {
        smbFileOutputStream.write(buf, 0, len);
    }
    fileInputStream.close();
    smbFileOutputStream.close();
}

I tried this answer, but didn't work for me. When I do normal copying(Copy and Paste) it only takes maximum of 8minutes for a 25MB file. But when I use my java program using this function its taking more than 20minutes. How can I make this copying faster? Thanks in advance.

解决方案

What I noticed is that jCIFS does "something" (afair jcifs.smb.SmbTransport.checkStatus(..)) for every chunk it reads - i.e. for each chunk that is read into the buffer. That means increasing your buffer size might really speed things up, although the real problem still exists, but only occurs 1 or 2 times having a lower impact on the overall time..

It helps a lot to set "jcifs.util.loglevel=3" and have a look what's really wrong..

In my case I had to set "jcifs.smb.client.dfs.disabled=false" in the end, as "jcifs.resolveOrder=DNS" didn't help..

这篇关于性能:使用JCIF将文件复制到Windows网络的速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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