HashSet and multithreading

I am working on Java 7.

I want to know if a method is containsthread safe for a HashSet object.

A HashSet is initialized with a single thread. Then we end the HashSet with an immutable collection ( Collections.unmodifiableSet). After initialization, several threads call only the method contains.

When I read the Javadoc, it is not clear to me.

In HashSet Javadoc we can read

This class implements the Set interface, supported by a hash table (actually an instance of HashMap).

...

Please note that this implementation is not synchronized.

And on the HashMap Javadoc , we can read:

, . , , . ( - , ; , , , .)

, contains .

, contains -?

: JVM (, IBM JVM)?

+4
1

, concurrency (, , ) . concurrency . , ( , ).

, concurrency, , ( ) . , contains() , , . " " Java, Java concurrency .

, Collections.unmodifiableSet() final. , , , contains() Set

+3

Source: https://habr.com/ru/post/1670156/


All Articles