The JBehave Embedder allows concurrent execution of stories. The multi-threading behaviour is controlled by setting the number of concurrent threads (which defaults to 1) via the EmbedderControls, or equivalently via @UsingEmbedder or the Maven goals.

The story execution can be configured to fail upon a timeout via the EmbedderControls, or equivalently via @UsingEmbedder or the Maven goals.

It is important to note that it's the entire story that is executed in one concurrent execution and that scenarios within the same story cannot be run concurrently. For each story execution a timeout can be set via the same configuration mechanism used to set the number of threads.

Configuring the ExecutorService

By default, the Embedder uses a fixed thread pool executor service, using the configured number of threads. Users can override the executor service using the Embedder's useExecutorService(ExecutorService) method.

Enqueing a single story

The Embedder API allow the enqueuing of a single story via the enqueueStory method. This is used for example by the WebQueue to provide a simple web facade to running stories in an asynchronous way.

The developer should take care that any static state shared between concurrently run stories should not introduce bugs or unwanted side effects. Indeed it is the opinion of the JBehave developer team that static state should be avoided.

It is possible that hundreds of stories could be run concurrently via this mechanism. There are tradeoffs though. Some other critical part of a system may fail of multiple threads are using it concurrently beyond its capacity.


Examples of use of multi-threading can be found in the Threads Example and the JBehave Tutorials.