Use the Prebuilt Classes of the Concurrency APIs Whenever Possible

Programming concurrent applications is difficult and error prone. If you must use synchronization in a program, follow these guidelines:

1. The vast majority of programmers should use existing collection classes and interfaces from the concurrency APIs that manage synchronization for you—such as the ArrayBlockingQueue class (an implementation of interface BlockingQueue) we discuss in Section 23.6. Two other concurrency API classes that you’ll use frequently are LinkedBlockingQueue and ConcurrentHashMap (each summarized in Fig. 23.22). The concurrency API classes are written by experts, have been thoroughly tested and debugged, operate efficiently and help you avoid common traps ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.