pass a new TestCase to a TestExecutor once it is ready with the previous TestCase?
This is a common question if I'm understanding you. You have a number of threads in a thread-pool but each thread has some context -- in this case a "web browser". You don't want to have to start up a new browser for every job submitted to the thread-pool.
Here are some ideas about how to accomplish this.
Have a
BlockingQueue
ofTestCase
objects. Each of your threads then initialize their browser and then dequeue from the queue ofTestCase
objects until the queue is empty or some shutdown boolean is set to true. You could the submit yourTestExecutor
objects into a thread-pool, but they would do their own dequeuing of theTestCase
objects though your own queue. You would not submit theTestCase
to the thread-pool.BlockingQueue<TestCase> testCaseQueue = new LinkedBlockingQueue<>(); for (TestCase test: tests) { testCaseQueue.add(test); } // now make your executors and run them in a thread-pool TestExecutor testExecutor = new TestExecutor(new FirefoxDriver(), testCaseQueue); ExecutorService threadPool = Executors.newCachedThreadPool(); threadPool.submit(testExecutor); ... // once you've submitted your last executor, you shutdown the pool threadPool.shutdown(); ... // inside of the executor, they dequeue tests from `testCaseQueue` while (!shutdown) { TestCase testCase = testCaseQueue.poll(0, TimeUnit.MILLISECONDS); if (testCase == null) { break; } ... }
Another idea would be to submit the
TestCase
to the thread pool and use aThreadLocal
to get the previously configured browser for the test. This is not as optimal because it makes it hard to terminate the browser appropriately when the tests have completed.