eBook:
$29.99
Formats:
$25.49
save 15%!
Print + free eBook + free PacktLib access to the book:
$79.98
Print cover: $49.99
$49.99
save 37%!
Free Shipping!
UK, US, Europe and selected countries in Asia.
Overview
Table of Contents
Author
Reviews
Support
Sample Chapters
Master all that Java 7 has to offer for concurrent programming Get to grips with thread management, the Fork/Join framework, concurrency classes and much more in this book and e-book A practical Cookbook packed with recipes for achieving the most important Java Concurrency tasks
Book Details
Language : English
Paperback : 364 pages [ 235mm x 191mm ]
Release Date : October 2012
ISBN : 1849687889
ISBN 13 : 9781849687881
Author(s) : Javier Fernández González
Topics and Technologies :
All Books, Oracle Other, Cookbooks, Enterprise, Java, Oracle
Table of Contents
Preface
Chapter 1: Thread Management
Chapter 2: Basic Thread Synchronization
Chapter 3: Thread Synchronization Utilities
Chapter 4: Thread Executors
Chapter 5: Fork/Join Framework
Chapter 6: Concurrent Collections
Chapter 7: Customizing Concurrency Classes
Chapter 8: Testing Concurrent Applications
Free Download Chapter
Index
- Chapter 1: Thread Management
- Introduction
- Creating and running a thread
- Getting and setting thread information
- Interrupting a thread
- Controlling the interruption of a thread
- Sleeping and resuming a thread
- Waiting for the finalization of a thread
- Creating and running a daemon thread
- Processing uncontrolled exceptions in a thread
- Using local thread variables
- Grouping threads into a group
- Processing uncontrolled exceptions in a group of threads
- Creating threads through a factory
- Chapter 2: Basic Thread Synchronization
- Introduction
- Synchronizing a method
- Arranging independent attributes in synchronized classes
- Using conditions in synchronized code
- Synchronizing a block of code with a Lock
- Synchronizing data access with read/write locks
- Modifying Lock fairness
- Using multiple conditions in a Lock
- Chapter 3: Thread Synchronization Utilities
- Introduction
- Controlling concurrent access to a resource
- Controlling concurrent access to multiple copies of a resource
- Waiting for multiple concurrent events
- Synchronizing tasks in a common point
- Running concurrent phased tasks
- Controlling phase change in concurrent phased tasks
- Changing data between concurrent tasks
- Chapter 4: Thread Executors
- Introduction
- Creating a thread executor
- Creating a fixed-size thread executor
- Executing tasks in an executor that returns a result
- Running multiple tasks and processing the first result
- Running multiple tasks and processing all the results
- Running a task in an executor after a delay
- Running a task in an executor periodically
- Canceling a task in an executor
- Controlling a task finishing in an executor
- Separating the launching of tasks and the processing of their results in an executor
- Controlling rejected tasks of an executor
- Chapter 5: Fork/Join Framework
- Introduction
- Creating a Fork/Join pool
- Joining the results of the tasks
- Running tasks asynchronously
- Throwing exceptions in the tasks
- Canceling a task
- Chapter 6: Concurrent Collections
- Introduction
- Using non-blocking thread-safe lists
- Using blocking thread-safe lists
- Using blocking thread-safe lists ordered by priority
- Using thread-safe lists with delayed elements
- Using thread-safe navigable maps
- Generating concurrent random numbers
- Using atomic variables
- Using atomic arrays
- Chapter 7: Customizing Concurrency Classes
- Introduction
- Customizing the ThreadPoolExecutor class
- Implementing a priority-based Executor class
- Implementing the ThreadFactory interface to generate custom threads
- Using our ThreadFactory in an Executor object
- Customizing tasks running in a scheduled thread pool
- Implementing the ThreadFactory interface to generate custom threads for the Fork/Join framework
- Customizing tasks running in the Fork/Join framework
- Implementing a custom Lock class
- Implementing a transfer Queue based on priorities
- Implementing your own atomic object
- Chapter 8: Testing Concurrent Applications
- Introduction
- Monitoring a Lock interface
- Monitoring a Phaser class
- Monitoring an Executor framework
- Monitoring a Fork/Join pool
- Writing effective log messages
- Analyzing concurrent code with FindBugs
- Configuring Eclipse for debugging concurrency code
- Configuring NetBeans for debugging concurrency code
- Testing concurrency code with MultithreadedTC
- Free Download Chapter
- You can download the Free Download Chapter from
- http://www.packtpub.com/sites/default/files/downloads/Building a
- Team and Working from Different Localities.pdf
Javier Fernández González
Javier Fernández González is a software architect with over 10 years experience with Java technologies. He has worked as a teacher, researcher, programmer, analyst, and now as an architect in all types of projects related to Java, especially J2EE. As a teacher, he has taught over 1,000 hours of training in basic Java, J2EE, and Struts framework. As a researcher, he has worked in the field of information retrieval, developing applications for processing large amount of data in Java and has participated as a co-author on several journal articles and conference presentations. In recent years, he has worked on developing J2EE web applications for various clients from different sectors (public administration, insurance, healthcare, transportation, and so on). He currently works as a software architect at Capgemini developing and maintaining applications for an insurance company.
Sorry, we don't have any reviews for this title yet.
Code Downloads
Download the code and support files for this book.
Submit Errata
Please let us know if you have found any errors not listed on this list by completing our errata submission form. Our editors will check them and add them to this list. Thank you.
Errata
- 21 submitted: last submission 29 Apr 2013
On page 2 of this book (that is, Preface), the link given for Chapter 9, http://www.packtpub.com/sites/default/files/downloads/Additional, should be http://www.packtpub.com/sites/default/files/downloads/Additional%20%20Information.pdf
On page 2 of this book (that is, Preface), the link given for Appendix, http://http://www.packtpub.com/sites/default/files/downloads/Concurrent, should be http://www.packtpub.com/sites/default/files/downloads/Concurrent%20%20Programming%20Design.pdf
Please don't refer to the link given in the TOC to download the free chapters. Instead, to download Chapter 9, go to: http://www.packtpub.com/sites/default/files/downloads/Additional%20%20Information.pdf and to download Appendix, go to: http://www.packtpub.com/sites/default/files/downloads/Concurrent%20%20Programming%20Design.pdf
On page 27, in the How it works... section, it is given that "After the first 10 seconds, we have 30 threads in the queue", which appears to be incorrect. The correct sentence is, "After the first 10 seconds, we have 30 events in the queue". Replace 30 threads with 30 events.
On page 39, in the fourth item, before the if statement, replace "System.out.printf("%s : %f\n",Thread.currentThread(). getId(),result);" with "System.out.printf("%s : %d\n",Thread.currentThread().getId(),result);". Here, %f is replaced with %d.
On page 157 and 160, replace "System.out.printf("Main: Canceled: %s\n",result.isCanceled());" with "System.out.printf("Main: Cancelled: %s\n",result.isCancelled());"
On page 181, point 1, replace "Create a class named Document. It will generate a string matrix that will simulate a document. public class Document {" with "Create a class named DocumentMock. It will generate a string matrix that will simulate a document. public class DocumentMock {"
On page 183, replace "protected Integer compute() { int result;" with "protected Integer compute() { int result=null;"
On page 201, "Point 19:for (int i=start; i<end; i++){if (array[i]==number) {replace withfor (int i=start; i<end; i++){if (numbers[i]==number) {Point 22:Task task1=new Task(array,start,mid,number,manager);Task task2=new Task(array,mid,end,number,manager);replace withTask task1=new Task(numbers,start,mid,number,manager);Task task2=new Task(numbers,mid,end,number,manager); "
On page 202, replace "public Task(int numbers[], int start, int end, int number,TaskManager manager){" with "public SearchNumberTask(int numbers[], int start, int end, int number, TaskManager manager){"
On page 204, replace "System.out.printf("Task: Canceled task from %d to%d",start,end);" with "System.out.printf("Task: Canceled task from %d to %d\n",start,end);" And in point 31, replace "Task task=new Task(array,0,1000,5,manager);" with "SearchNumberTask task=new SearchNumberTask(array,0,1000,5,manager);
In Chapter 6, <i>Using thread-safe lists with delayed elements</i>, sometimes the name DelayedQueue is used when the correct name is DelayQueue.
On page 247, replace point 11 with:"Create a list of Future objects parameterized with the String class to store theresultant objects of the tasks you're going to send to the executor.List<Future<String>> results=new ArrayList<>();"
On page 277, replace point 1. with "Create a class named MyAbstractQueuedSynchronizer that extends the AbstractQueuedSynchronizer class.public class MyAbstractQueuedSynchronizer extendsAbstractQueuedSynchronizer {."
On page 269, in point 11 and point 19, Task class have to be replaced by MyRecursiveTask.
n page 302, replace point 16 with:"Display the number and the name of the threads queued for the lock.System.out.printf("Lock: Queued Threads: %s\n",lock.hasQueuedThreads());if (lock.hasQueuedThreads()){"</p><p>On page 310, replace bullet 13 with:"Implement the showLog() method that receives Executor as parameter.Write information about the size of the pool, the number of tasks, and the statusof the executor.private static void showLog(ThreadPoolExecutor executor) {System.out.printf("*********************\n");System.out.printf("Main: Executor Log\n");"
On page 317, replace "sb.append(record.getMessage()+"\n");" with "sb.append(record.getMessage()+"\n");"
On page 57, in the declaration of the storage object, replace "private List<Date> storage;" with "private LinkedList<Date> storage;".
On page 155, replace the name of the method schedulledWithFixedRate() with schedulledWithFixedDelay().
On page 31, numbered bullet 3, replace "This method will create an object of the UnsafeTask class and start three threads using that object, sleeping for 2 seconds between each thread." with "This method will create an object of the UnSafeTask class and start ten threads using that object"
On page 58, numbered bullet 3, replace "storage.offer(new Date())" with "storage.add(new Date())".
Frequently bought together
+
=
50% Off
the eBooks
Buy both these recommended eBooks together and get 50% off the total price
What you will learn from this book
Master the basics of thread management and synchronization before diving into higher level concurrency tasks Get to grips with exciting new concurrency features of Java 7, including the Phaser Class and the Fork/Join Framework Successfully delegate thread management to executors Customize some of the most useful classes of the Java concurrency API with real-world examples Learn to use high-level Java utilities to manage synchronization between threads Get a sneak peek at using Eclipse and NetBeans for debugging concurrency code Avoid problems with data inconsistency by learning the data structures you have to use in concurrent applications Take advantage of a bonus appendix packed with tips that every programmer should consider when developing a concurrent application
In Detail
Java remains the global standard for developing various applications and enterprise software, and the launch of Java 7 brings with it exciting new capabilities for concurrent programming by way of the concurrency utilities enhancement. This allows developers to make the most of their applications with parallel task performance. "Java 7 Concurrency Cookbook" covers all elements of the Java concurrency API, providing essential recipes for taking advantage of the exciting new capabilities.On your computer, you can listen to music while you edit a Word document and read your emails, all at once! This is because your operating system allows the concurrency of tasks, much like the Java platform which offers various classes to execute concurrent tasks inside a Java program. "Java 7 Concurrency Cookbook" covers the most important features of the Java concurrency API, with special emphasis on the new capabilities of version 7. With each version, Java increases the available functionality to facilitate development of concurrent programs. This book covers the most important and useful mechanisms included in version 7 of the Java concurrency API, so you will be able to use them directly in your applications."Java 7 Concurrency Cookbook" includes recipes to enable you to achieve everything from the basic management of threads and tasks, to the new Fork /Join framework, through synchronization mechanisms between tasks, different types of concurrent tasks that Java can execute, data structures that must be used in concurrent applications and the classes of the library that can be customized.With the step-by-step examples in this book you’ll be able to apply the most important and useful features of the Java 7 concurrency API.
Approach
"Java 7 Concurrency Cookbook" is a practical Cookbook packed with real-world solutions. Intermediate–advanced level Java developers will learn from task-based recipes to use Java’s concurrent API to program thread safe solutions.
Who this book is for
If you are a Java developer who wants to take your knowledge of concurrent programming and multithreading further, as well as discover the new concurrency features of Java 7, then "Java 7 Concurrency Cookbook" is for you.You should already be comfortable with general Java development practices and a basic grasp of threads would be an advantage.