Domino Java Agent中的jcifs不释放线程

时间:2018-07-31 15:15:31

标签: java lotus-domino jcifs

该代理第二次运行后,我收到以下消息。我添加了一个5秒的超时循环,如下所示:Domino Java agent using JCIFS - Error cleaning up agent threads

jcifs.smb.SmbException: Transport1['*sharename/IP+port 445*'] timedout waiting for response to Trans2QueryPathInformation[command=SMB_COM_TRANSACTION2,received=false,errorCode=0,flags=0x0018,flags2=0xC803,signSeq=0,tid=1,pid=38217,uid=1,mid=26,wordCount=15,byteCount=91,totalParameterCount=90,totalDataCount=0,maxParameterCount=2,maxDataCount=40,maxSetupCount=0,flags=0x00,timeout=0,parameterCount=90,parameterOffset=66,parameterDisplacement=0,dataCount=0,dataOffset=156,dataDisplacement=0,setupCount=1,pad=1,pad1=0,informationLevel=0x101,filename='*internal protected share*']

jcifs.util.transport.TransportException: Transport1['*sharename/IP+port 445*'] timedout waiting for response to Trans2QueryPathInformation[command=SMB_COM_TRANSACTION2,received=false,errorCode=0,flags=0x0018,flags2=0xC803,signSeq=0,tid=1,pid=38217,uid=1,mid=26,wordCount=15,byteCount=91,totalParameterCount=90,totalDataCount=0,maxParameterCount=2,maxDataCount=40,maxSetupCount=0,flags=0x00,timeout=0,parameterCount=90,parameterOffset=66,parameterDisplacement=0,dataCount=0,dataOffset=156,dataDisplacement=0,setupCount=1,pad=1,pad1=0,informationLevel=0x101,filename='*internal protected share*']

我添加了一个5秒的循环以使连接超时,如下面的代码所示:

import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbFile;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.List;





public class CopyFileUsingJCIFS {

    public static void main(String userName, String password, String sourcePath, String destinationPath) {

        try {
            jcifs.Config.setProperty("DEFAULT_SO_TIMEOUT", "1000");
            jcifs.Config.setProperty("jcifs.smb.client.soTimeout", "1000");
            jcifs.Config.setProperty("DEFAULT_CONN_TIMEOUT", "1000");
            jcifs.Config.setProperty("jcifs.smb.client.CONN_TIMEOUT", "1000");

            NtlmPasswordAuthentication authentication = new NtlmPasswordAuthentication("CWOPA;" + userName + ":"
                    + password);
            SmbFile home = new SmbFile(sourcePath, authentication);

            if (home.isDirectory()) {
                List<SmbFile> files = Arrays.asList(home.listFiles());
                for (SmbFile file : files) {
                    if (file.isDirectory()) {
                        System.out.println("Directory: " + file.getName());
                    }
                    if (file.isFile()) {
                        String chkFilename = file.getName();
                        String chkExtension = chkFilename.substring(chkFilename.length() - 4);
                        if (!(chkExtension.equals("done") || file.isDirectory())) {

                            System.out.println("File: " + file.getName());
                            InputStream is = file.getInputStream();

                            OutputStream os = new FileOutputStream(destinationPath + file.getName());

                            byte[] buf = new byte[16 * 1024 * 1024];
                            int len;
                            while ((len = is.read(buf)) > 0) {
                                os.write(buf, 0, len);
                            }

                            if(!chkExtension.contains("txt")){
                            SmbFile homeArchive = new SmbFile(sourcePath + file.getName() + ".done", authentication);
                            file.renameTo(homeArchive);
                            homeArchive = null;
                            }

                            os.flush();
                            os.close();
                            is.close();

                            pause(); // added 5 seconds in order to allow jcifs
                                        // to drop its' threads
                            // https://stackoverflow.com/questions/30475624/domino-java-agent-using-jcifs-error-cleaning-up-agent-thread
                            System.out.println("Closed, flushed, and renamed " + file.getName());
                        } else {
                            System.out.println("Bypassed " + file.getName());
                        }
                    }    
                }

            }
            System.out.println("home Exists = " + home.exists());
            System.out.println("home attributes are " + home.getAttributes());
            home = null;

        } catch (Exception e) {
            e.printStackTrace();
        } finally {

        }

        System.gc();
    }

    static void pause() {
        long Time0 = System.currentTimeMillis();
        long Time1;
        long runTime = 0;
        while (runTime < 5000) {
            Time1 = System.currentTimeMillis();
            runTime = Time1 - Time0;
        }
    }

}

线程转储在第一次运行时显示以下内容:

Dump the current threadgroup:

ThreadGroup UTG: JavaAgent, objid = -9513271
  subgroups  = 0
  total threads = 2

Thread Name, ThreadID, ThreadGroup
Transport1, -1492287803, UTG: JavaAgent
AgentThread: JavaAgent, 264811003, UTG: JavaAgent


Dump the current threadgroup after garbage collection:

ThreadGroup UTG: JavaAgent, objid = -9513271
  subgroups  = 0
  total threads = 2

Thread Name, ThreadID, ThreadGroup
Transport1, -1492287803, UTG: JavaAgent
AgentThread: JavaAgent, 264811003, UTG: JavaAgent

Error cleaning up agent threads

0 个答案:

没有答案