Concurrent Collections Flashcards
What is Blocking Queue?
Blocking Queue is just like a queue except that it includes methods that will wait a specific amount of time to complete an operation
What are the blocking queue waiting methods?
offer(E e, long timeout, TimeUnit unit) : Adds item to the queue waiting for specified time, returning false if time elapses when disk space available
poll(long timeout, TimeUnit unit): Retrieves and removes an item from Queue, waiting specified time, returning null if time elapses
Both throw InterruptedCheckedExceptions
What is Linked Blocking queue?
Maintains a linked list between elements
What is LinkedBlockingDeque?
LinkedBlockingQueue class maintains the doubly linked list between elements and implements BlockingDeque interface which inturn extends Deque
What are the methods in LinkedBlockingDeque?
- offerFirst(E e, long timeout, TimeUnit time)
- offerlast(E e, long timeout, TimeUnit unit)
- pollFirst(long timeout, TimeUnit unit)
- pollLast(long timeout, TimeUnit unit)
What are the classes under SkipList?
ConcurrentSkipListSet and concurrentSkipListMap.
They are the counterparts of TreeSet and TreeMap
What should be kept on mind on seeing SkipList and SkipMap on the exam?
They are Sorted concurrent collections
What is special on CopyOnWriteArrayList and CopyOnWriteArraySet concurrent classes?
These classes copy all their elements to a new underlying structure anytime an element is added, modified or removed from collections.
What does a modified element mean?
They mean a refernece in the collection is changed.
Modifying the actual contents of the collection will not cause a new structure to be allocated
What is the problems with CopyOnWriteCollections?
It can occupy lots of space in memory since a new collection structure needs to be allocated anytime
Where does CopyOnWrite classes mostly being used?
In multi-threaded environment, where reads are far more common than writes
Best practice while Using Synchronized collections?
- When we use synchronized version of colections, they synchronize the access on data elements such as set() and get() on that collections, they dont synchronize access on any iterators that we create from synchronized collections.
So, we must use a synchronization block if you need to iterate over any of returned collections
What is the most powerful features of Stream API?
It has a built in concurrency support
What is serial stream?
A stream in which the results are ordered, with only one entry being processed at a time
What is a parallel streams?
A stream that is capable of processing results concurrently using multiple threads