ThreadGuard
This class is only available in the Java Binding
ThreadGuard checks that a driver is called only from the same thread that created it. Threading issues especially when running tests in Parallel may have mysterious and hard to diagnose errors. Using this wrapper prevents this category of errors and will raise an exception when it happens.
The following example simulate a clash of threads:
The result shown below:
As seen in the example:
protectedDriver
Will be created in Main thread- We use Java
Runnable
to spin up a new process and a newThread
to run the process - Both
Thread
will clash because the Main Thread does not haveprotectedDriver
in it’s memory. ThreadGuard.protect
will throw an exception.
Note:
This does not replace the need for using ThreadLocal
to manage drivers when running parallel.