Executing method in multiple threads
Methods annotated with @Parallel
will be executed in multiple threads (depending on the threads
annotation parameter):
public class FooTest { @Test public void canProcessInParallel() { final Foo foo = new Foo(); new Runnable() { @Override @Parallel(threads = 15) public void run() { foo.process(); } }.run(); } }
The above code will execute the run()
method in 15 threads (15 separate invocations). As a result, the process()
method of the Foo
class will also be executed in those threads.
The mechanism is implemented with AOP/AspectJ. Read how to integrate it into your pom.xml
.