Both execute methods of the
Request are blocking,
which means that a thread is required for each robot execution. The
examples we have looked at until now have all executed the robot
directly on the main thread, which is typically not preferable as you
can only execute a single robot at a time in a sequential manner.
Let's look at an example that will execute two tutorial robots in
parallel. This example uses the
library for multithreading.
The above example creates a
two threads, we then creates four
execute them on the thread pool. Since the thread pool has two threads,
two robots will start to execute immediately, the remaining two will be
parked in the
LinkedBlockingQueue and executed in order as
the two first robot finish their execution and the thread pool threads
Please note that the
Request is mutable, to avoid
raise conditions the Request is cloned inside the execute method.
Request is mutable you should never modify the same
Request on separate threads.