I have many threads. Each thread creates and uses it's own WebClient (HtmlUnit framework). No one thread uses WebClient's instance from other thread. Is it thread safe?
A thread-safe class is a class that guarantees the internal state of the class as well as returned values from methods, are correct while invoked concurrently from multiple threads. The collection classes that are thread-safe in Java are Stack, Vector, Properties, Hashtable, etc.
A thread-safe routine is one that can be called concurrently from multiple threads without undesirable interactions between threads. A routine can be thread safe for either of the following reasons: It is inherently reentrant. It uses thread-specific data or lock on mutexes.
From the documentation
Note: a WebClient instance is not thread safe. It is intended to be used from a single thread.
As long as each thread creates its own WebClient, you won't have any issues. From what you said, you're doing the right thing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With