Review : Java 7 Concurrency Cookbook
The Java 7 Concurrency Cookbook, containing over 60 examples show you how to do multithreaded programming in Java. It shows varies threading topics from beginner level to advanced level, including thread management like create, interrupt and monitor thread, using Java 5 Executor
frameworks to run or schedule threads, and the latest Java 7 fork/Join
Frameworks to distribute threads.
My favorite is chapter 3, showing 5 examples of common concurrent mechanisms or patterns – “Semaphores“, “CountDownLatch“, “CyclicBarrier“, “Phaser” and “Exchanger“, and how these mechanisms solve existing threading problem. In additional, at the end of the chapter, it surprises me by showing how to test Java concurrent code in both Eclipse and NetBean.
See following section to know what will you learn from this book.
Chapter 1: Thread Management
Hello world chapter with many useful examples to show you the basic of Thread management.
Skills are learned:
- How to create, interrupt, sleep and resume a thread.
- How to program a Daemon thread.
- How to process thread exceptions.
- How to grouping threads into a group.
Chapter 2: Basic Thread Synchronization
Thread synchronization to control how the multiple threads read and write the same data, files or database (shared resources),
Skills are learned:
- How to use the
synchronized
keyword, to synchronize a method. - How to use the
Lock
interface and its implementations, to synchronize a block of code. - How to do single / multiple conditions in synchronized code, using
wait()
,notify()
, andnotifyAll()
.
Chapter 3: Thread Synchronization Utilities
Examples to show you the five common concurrent mechanisms or patterns to synchronize multiple threads, and what problem it is solving.
Skills are learned:
- Semaphores – A counter that controls the access to one or more shared resources.
- CountDownLatch – Allows a thread to wait for the finalization of multiple operations.
- CyclicBarrier – Allows the synchronization of multiple threads in a common point.
- Phaser – Controls the execution of concurrent tasks divided in phases.
- Exchanger – Provides a point of data interchange between two threads.
Chapter 4: Thread Executors
How to work with the Java 5, Executor frameworks – Executor
, ThreadPoolExecutor
and etc. It like a scheduler to run a single or multiple threads at the specified time or interval.
Skills are learned:
- How to create a thread executor
- How to run a task after a delay.
- How to run a task periodically.
- How to controlling task finishing or canceling.
Chapter 5: Fork/Join Framework
New Java 7 Fork/Join Framework.
Skills are learned:
- What’s Java 7 Fork/Join Framework, and a simple hello world example.
- How to joining the results from the divided tasks.
- How to canceling a task.
Chapter 6: Concurrent Collections
Introduce Java collections that used in the concurrent programming.
Skills are learned:
- What’s blocking and non-blocking collections.
- Examples to use blocking and non-blocking thread-safe list.
ConcurrentNavigableMap
example.- How to generate concurrent random numbers with
ThreadLocalRandom
. - How to use atomic variables – e.g
AtomicLong
, and atomic arrays – e.gAtomicIntegerArray
.
Chapter 7: Customizing Concurrency Classes
This chapter shows you how to customize existing concurrency classes to suit your needs. Often times, you don’t need this, but good to know.
Skills are learned:
- Implementing a priority-based
Executor
class - How to use
ThreadFactory
. - Customizing tasks running in a scheduled thread pool and in the Fork / Join framework.
- How to implement a custom
Lock
class. - How to implement your own atomic object.
Chapter 8: Testing Concurrent Applications
This chapter shows you how to test in your concurrent program.
Skills are learned:
- How to monitor
Lock
,Phaser
,Executor
framework and Fork/Join pool. - How to configure Eclipse and NetBeans for debugging concurrency code.
- How to analyze concurrent code with FindBugs
Conclusion
This book contains a lot of easy to follow examples, and well-explained at the end of each example, except the chapter 6 and chapter 7, which required some years of threading background to understand. For beginners who want to learn threading in Java, this “Java 7 Concurrency Cookbook” is the best book to study. For experienced developers, you also can treat this as a complete reference of “Java Concurrency”.
What if compare with the classic Java Concurrency in Practice? I think both books are targeted for different developer level. IMHO, the classic “Java Concurrency in Practice” is for advanced level, its snippet code is followed by a few pages of explanations is great, but not suitable for anyone. And this Java 7 Concurrency Cookbook is for beginner and immediate level, the example is easy to understand and ready to modify for your project use.
Thanks for sharing it..
Please share this book with me.
Thanks
Shyam
i like open source stuffs only
Hi, Can you please send that ebook to me.
Here is my email id.
[email protected]
Hmm is anyone else encountering problems with the images on this blog loading?
I’m trying to figure out if its a problem on my end or if it’s the
blog. Any suggestions would be greatly appreciated.
I like to know the Thread concepts because am the beginners and interested to know it.Am Eagerly looking for this book how it is explained about this concept and having hope this book should make understandable and easier to learn too.
Thanks,for sharing this book .