You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Concurrency API includes classes and interfaces which provide easy ways to implement thread safety on collection types, as well as improving performance.
We don't even need these methods as they call the implementation from ConcurrentHashMap!
🟥 7.4.2 Understanding Memory Consistency Errors
Memory consistency errors occur when two thread have inconsistentg views of the same data
JVM will throw a ConcurrentModificationException when two threads attempt to modify a non-concurrent collection - this can occur even in a single-thread:
We have two classes which implement blocking interfaces: LinkedBlockingQueue and LinkedBlockingDeque
BlockingQueue has methods which wait a specied amount of time to finish an operation:
poll(long timeout, TimeUnit unit) - retrieves and removes item in alotted time, returns null if time elapses.
BlockkingDeque has the following methods:
offerFirst(E e, long timeout, TimeUnit unit) - adds item to front of queue, waiting the alotted time. Returns false if time elapses
offerLast(E e, long timeout, TimeUnit unit) - adds item to back of queue, waiting the alotted time.
pollFirst(long timeout, TimeUnit unit) - retrieves and removes the first item, returns null if time elapses
pollLast(long timeout, TimeUnit unit) - retrieves and removes last item.
🟡 Understanding SkipList Collections
The ConcurrentSkipListMap and ConcurrentSkipListSet are concurrent versions of their ordered counterparts: TreeMap and TreeSet
🟡 Understanding CopyOnWrite Collections
The CopyOnWriteArrayList, and CopyOnWriteArraySet classes copy all their eleents to a new underlying structure anytime an element is removed, added or modified - reference has changed.
These classes are useful when you need to iterate over a collection in a multithreaded environment