You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "谢裕亮 (Jira)" <ji...@apache.org> on 2022/09/01 09:18:00 UTC

[jira] [Created] (VFS-824) Http4FileSystem - Connection pool shut down

谢裕亮 created VFS-824:
-----------------------

             Summary: Http4FileSystem - Connection pool shut down
                 Key: VFS-824
                 URL: https://issues.apache.org/jira/browse/VFS-824
             Project: Commons VFS
          Issue Type: Bug
         Environment: Java8

windows
            Reporter: 谢裕亮


import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.cache.WeakRefFilesCache;
import org.apache.commons.vfs2.impl.StandardFileSystemManager;
import org.apache.commons.vfs2.provider.AbstractFileSystem;

import java.io.IOException;

/**
* @Date 2022年09月01日 14:10
* @Description TODO
*/
public class TestHttpFileSystem {
public static void main(String[] args) throws IOException, InterruptedException {
try (StandardFileSystemManager fileSystemManager = new StandardFileSystemManager()) {
fileSystemManager.setConfiguration(StandardFileSystemManager.class.getResource("providers.xml"));
fileSystemManager.setFilesCache(new WeakRefFilesCache());
// fileSystemManager.setFilesCache(new SoftRefFilesCache());
fileSystemManager.init();

String path = "http4://images5.alphacoders.com/796/796745.png";
AbstractFileSystem http4FileSystem = getFile(fileSystemManager, path);
System.out.println(http4FileSystem.isReleaseable());

while (!http4FileSystem.isReleaseable()) {
System.out.println("Try GC");
// GC
System.gc();
}
// free resource
// http4FileSystem.httpclient is closed
fileSystemManager.freeUnusedResources();
// fileSystemManager.closeFileSystem(http4FileSystem);

// get file again
getFile(fileSystemManager, path);
// Caused by: java.lang.IllegalStateException: Connection pool shut down
// at org.apache.http.util.Asserts.check(Asserts.java:34)
// at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:269)
// at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176)
// at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
// at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
// at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
// at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
// at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
// at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
// at org.apache.commons.vfs2.provider.http4.Http4FileObject.executeHttpUriRequest(Http4FileObject.java:191)
// at org.apache.commons.vfs2.provider.http4.Http4FileObject.doGetType(Http4FileObject.java:156)
// at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1375)
// ... 2 more
}
}

private static AbstractFileSystem getFile(FileSystemManager fileSystemManager, String path) throws FileSystemException {
FileObject fileObject = fileSystemManager.resolveFile(path);
System.out.println("File Type Is " + fileObject.getType());

return (AbstractFileSystem) fileObject.getFileSystem();
}
}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)