JCIFS读取远程服务器文件过慢的解决方法

时间:2024-01-02 18:16:02

JCIFS读取远程服务器文件过慢的解决方法

发表于3年前(2013-07-12 11:23)   阅读(1174) | 评论(0

// 我要收藏";
var favor_del = "取消收藏";
var favor_ok = "

已成功添加到收藏夹

我的收藏夹 | 关闭

";
function delete_favor(obi_id, obj_type){
$('#attention_it').html(favor_add);
$("#p_attention_count").load("/action/favorite/cancel?type="+obj_type+"&id="+obi_id, {user: ''});
}
function add_to_favor(obj_id, obj_type){
if(confirm('必须登录后才能收藏,是否现在登录?')){
location.href="http://www.oschina.net/home/login?goto_page="+encodeURIComponent(location.href);
}
}
function close_favor(elem_id){
$('#favor_trigger').poshytip('destroy');
}
function setTag(tv){
var t = $("._favor_input");
var value = t.val();
var tags = value.replace(/,/ig,',').split(',');
var exist = false;
value = $.map(tags,function(v,i){
if($.trim(tv) == $.trim(v)){
exist = true;
return undefined;
}
return v;
}).join(',');
if(exist){
t.val(value);
return;
}
if(value!="")
t.val(value+","+tv);
else
t.val(tv)
}
function ltrim(str){
var whitespace = new String(" \t\n\r");
var s = new String(str);
if (whitespace.indexOf(s.charAt(0)) != -1){
var j=0, i = s.length;
while (j = 0 && whitespace.indexOf(s.charAt(i)) != -1){
i--;
}
s = s.substring(0, i+1);
}
return s;
}

function trim(str){
return rtrim(ltrim(str));
}
// ]]>
0人收藏此文章,
//
我要收藏
//

0

与windows explorer打开相同的文件相比,JCIFS默认情况下要慢太多了。我找了大半天,总算找出了解决方法,增加如下配置,则读取速度会有质的飞跃,我这边从7s提升至0.2s:

1
System.setProperty("jcifs.smb.client.dfs.disabled", "true");

至于原因嘛,我也不知道,我是从此网站捞到的一条配置:

http://samba.2283325.n4.nabble.com/Peformance-questions-td4644647.html

执行程序代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
private static final int BUFFER_SIZE = 1024;
 public static void main(String[]args) throws Exception {
    //SmbFile file = new SmbFile("smb://finchina;daieel:123456@192.168.100.246/Soft/sc8 key.txt");     //SmbFile file = new SmbFile("smb://10.15.97.181/xx部资料库/工作文档/查询逻辑.txt");d     //http://samba.2283325.n4.nabble.com/Peformance-questions-td4644647.html     System.setProperty("jcifs.smb.client.dfs.disabled", "true");
         
    long startTime = System.currentTimeMillis();
    UniAddress dc = UniAddress.getByName("192.168.100.5");  
    NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("fgina", "xiajl", "orange");  
    SmbSession.logon(dc, authentication);  
    SmbFile file = new SmbFile("smb://192.168.100.5/edse/users.txt",  authentication);  
      
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    BufferedInputStream in = new BufferedInputStream(new SmbFileInputStream(file));
    //SmbFileInputStream in = new SmbFileInputStream(file) ;  //建立smb文件输入流     byte buffer[] = new byte[BUFFER_SIZE] ;
    int count = -1
    while((count = in.read(buffer,0,BUFFER_SIZE)) != -1) {
        out.write(buffer, 0, count);
    }
    String content = new String(out.toByteArray(),"GBK");
    in.close();
    System.out.println(System.currentTimeMillis() - startTime);
      
    System.out.println(content);
}