Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HtmlUnit: one WebClient per thread - is it thread safe?

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?

like image 481
den123 Avatar asked Oct 21 '12 19:10

den123


People also ask

Which data structure is 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.

What are thread-safe libraries?

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.


1 Answers

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.

like image 133
Augusto Avatar answered Sep 18 '22 10:09

Augusto