jxbrowser中获取Browser browser Channel获取异常失败

Getting Exception Failed to get Browser browser Channel in jxbrowser

我正在使用 jxbrowser,

我想使用 browser.saveWebpage 下载 url 列表

public class Downloader{
public Downloader(String url) {
           System.setProperty("teamdev.license.info", "true");
           LoggerProvider.getChromiumProcessLogger().setLevel(Level.OFF);
           Browser browser = new Browser(BrowserType.LIGHTWEIGHT);

         browser.addLoadListener(new LoadAdapter() {
             @Override
             public void onFinishLoadingFrame(FinishLoadingEvent event) {
                 if (event.isMainFrame()){
                      String filePath = "D:\Downloads\index"+System.currentTimeMillis()+".html";
                      String dirPath = "D:\Downloads\resources";
                      event.getBrowser().saveWebPage(filePath, dirPath, SavePageType.ONLY_HTML);
                 }
             }
         });
        browser.loadURL(url);
        if(!browser.isLoading())
        {
            browser.stop());
        }
    }


public static void main(String args[])
{
      JxBrowserDemo jxBrowserDemo=null;
        String yourInputFile="D:/file.txt";
        ArrayList<String> lines=getUrls(yourInputFile); //read urls from file 

for(int i=0; i<lines.size(); i++)
        {  
             Thread.sleep(5000);
             jxBrowserDemo=new JxBrowserDemo(lines.get(i));
        }
}   

}

保存页面在特定时间之前工作正常然后抛出此异常

Exception in thread "main" java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:58) Caused by: com.teamdev.jxbrowser.chromium.internal.ipc.IPCException: Failed to g et Browser browserChannel 969 at com.teamdev.jxbrowser.chromium.Browser.a(SourceFile:376) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:200) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:172) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:139) at com.teamdev.jxbrowser.chromium.Browser.(SourceFile:125) at com.teamdev.jxbrowser.chromium.demo.JxBrowserDemo.(JxBrowserDem o.java:67) at com.teamdev.jxbrowser.chromium.demo.JxBrowserDemo.main(JxBrowserDemo. java:143) ... 5 more

请帮忙:)

"Failed to get Browser browserChannel 969" 消息很可能表明由于某种原因 Chromium 引擎无法创建浏览器实例并为其打开通道。 Chromium 引擎可能对同时创建的浏览器实例数量有一些限制。这些限制可能取决于内存大小、环境配置等。由于您已经创建了 968 个浏览器实例而没有释放它们,这可能是出现此异常的原因。 另请注意,您有内存泄漏,因为您为每个 URL 创建了新的浏览器实例,并且在此 URL 浏览器实例处理后不调用 dispose() 方法它是 URL .

browser.stop(); 行是不必要的。 在调用 saveWebPage() 方法之后,您应该等到网页被保存并释放浏览器实例。 请看下面的示例代码:

                final int maxWaitingTime = 10000;
                final int sleepTime = 50;
                int currentWaitingTime = 0;
                File indexHTML = new File(filePath);
                File resourcesFolder = new File(dirPath);
                while (!indexHTML.exists() || !resourcesFolder.exists()) {
                    TimeUnit.MILLISECONDS.sleep(sleepTime);
                    currentWaitingTime += sleepTime;
                    if (currentWaitingTime == maxWaitingTime)
                        throw new RuntimeException(new TimeoutException("The web page could not be saved."));
                }
                event.getBrowser().dispose();