开发者

Setting off multi-threaded stopwatch instances (commandHolder got filled during execution of doCommandWithoutWaitingForAReponse exception)

I am trying to do something conceptually simple... We have multiple portlets loading on a Dashboard. I need to measure the load time that each takes. I have implemented a simple StopWatch class, and need to run multiple instance of it simultaneously, for each portlet, while the Dashboard is loading. So the parameters supplied will be:

  1. The portlet name
  2. The element to be checked, indicating a successful load.

Here is the StopWatch class:

 public class StopWatch implements Runnable {
        private long startTime;
        private long stopTime;
        private String tElement;
        private String tPortletName;

        public StopWatch(String portletName,String element) {
         tElement = element;
         tPortletName = portletName;

        }

        public void start() {
     startTime = System.currentTimeMillis();
        }
        public void stop() {
     stopTime = System.currentTimeMillis();
        }
        public long getTime() {
     return stopTime - startTime;
        }

 @Override
 public void run() {
  selenium.selectFrame(tPortletName);
                StopWatch sw = new StopWatch();
  sw.start();
  while (selenium.isElementPresent(tElement)==false)
              try {
     Thread.sleep(10);
    } catch (InterruptedException e) {
     e.printStackTrace();
    }
   sw.stop();
   long time = sw.getTime();
   System.out.println(tPortletName+" load time="+time);
  }
   }

In the calling program,

StopWatch sw1 = new StopWatch(portlet1,element1);
StopWatch sw2 = new StopWatch(portlet2,element2);
ExecutorService threadExecutor = Executors.newFixedThreadPool(3);

threadExecutor.execute(sw1); // start task1
threadExecutor.execute(sw2); // start task2

Upon running this, I get the following exception:

com.thoughtworks.selenium.SeleniumException: ERROR Server Exception: command开发者_开发技巧Holder got filled during execution of doCommandWithoutWaitingForAReponse

Any clues on what causes this?


Most likely the reason is that you are sending commands faster then Selenium can process them.

Anyway this approach should not work since DefaulSelenium and other Selenium classes are not synchronized so if you most likely you will get deadlocks or unpredictable results.

I think you will have to test this in two steps: load dashboard, wait for first portlet, then reload dashboard and wait for second portlet. Do all of this in the main thread, something like:

private void waitForPortlet(String portletName, String element) {
    long startTime = System.currentTimeMillis();

    while (selenium.isElementPresent(element) == false)
        try {
            Thread.sleep(10);
        } catch (Exception e) {
            e.printStackTrace();
        }

    long stopTime = System.currentTimeMillis();

    System.out.println(portletName + " load time=" + (stopTime - startTime));
}

And use:

    waitForPortlet(name1, element1);

    selenium.refresh();

    waitForPortlet(name2, element2);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜