Concurrent collection classes

The concurrent collection classes provide more scalability and performance than other collection classes, such as HashMap or Hashtable. The following are useful concurrent classes provided in the java.util.concurrent package:

  • ConcurrentHashMap: This is similar to HashMap and Hashtable, but it has been designed to work in concurrent programming without the need for explicit synchronization. Hashtable and ConcurrentHashMap are both thread-safe collections, but ConcurrentHashMap is more advanced than Hashtable. It does not lock the entire collection for synchronization, so it is very useful when there are a lot of updates and fewer concurrent reads.
  • BlockingQueue: The producer-consumer pattern is the most common design pattern in asynchronous programming, and the BlockingQueue data structure can be very useful in these asynchronous scenarios.
  • DelayQueue: This is an infinite size blocking queue of elements where an element can only be taken when its delay has expired. If multiple elements delay expiry, then the element with the longest delay expiration will be taken first.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset