File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -226,15 +226,23 @@ synchronized void nextPlayer() {
226226Common data types are typically ** not** multithread safe.
227227This means only one thread can safely access them at a time.
228228For example:
229- - ` ArrayList `
230- - ` LinkedList `
231- - ` HashMap `
232- - ` HashSet `
229+
230+ ``` java
231+ // Not thread-safe data types:
232+ List list = new ArrayList ();
233+ Queue queue = new LinkedList ();
234+ Map map = new HashMap ();
235+ Set set = new HashSet ();
236+ ```
233237
234238If you need multiple threads to be able to access the data types at the same time,
235239consider these following thread-safe data types instead:
236- - ` Collections.synchronizedList(new ArrayList()) `
237- - ` CopyOnWriteArrayList `
238- - ` LinkedBlockingDeque `
239- - ` ConcurrentHashMap `
240- - ` ConcurrentHashMap.newKeySet() `
240+
241+ ``` java
242+ // Thread-safe data types
243+ List frequentlyModifiedList = Collections . synchronizedList(new ArrayList ());
244+ List infrequentlyModifiedList = new CopyOnWriteArrayList ();
245+ Queue queue = new LinkedBlockingDeque ();
246+ Map map = new ConcurrentHashMap ();
247+ Set set = ConcurrentHashMap . newKeySet();
248+ ```
You can’t perform that action at this time.
0 commit comments