信号量不适用于PhantomJs DesiredCapabilities

时间:2017-09-22 12:11:05

标签: java multithreading selenium-webdriver phantomjs semaphore

当我使用注释//driver = new PhantomJSDriver(desiredCapabilities);运行此代码时,一切正常。我只能看到两个" PhantomJS"系统过程。

2 process但是,如果我使用未注释的driver = new PhantomJSDriver(desiredCapabilities);运行此代码,则数量为#34; PhantomJS"系统处理超过2:more than 2 ...为什么?

    PhantomJsDriverManager.getInstance().setup();
    Semaphore s = new Semaphore(2);
    for (int i = 0; i < 10; i++) {
        s.acquire();

        new Thread() {
            public void run() {
                PhantomJSDriver driver = new PhantomJSDriver();
                try {
                    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
                    System.out.println("Start: " + getName());
                    desiredCapabilities.setJavascriptEnabled(true);
                    driver = new PhantomJSDriver(desiredCapabilities);
                    driver.get("https://community.oracle.com/");
                    driver.quit();
                    System.out.println("Stop: " + getName());
                } catch (Exception e) {
                    driver.quit();
                } finally {
                    driver.quit();
                    s.release();
                }
            }
        }.start();

    }
}

0 个答案:

没有答案