You are previewing Java 7 Concurrency Cookbook.

Java 7 Concurrency Cookbook

Cover of Java 7 Concurrency Cookbook by Javier Fernández González Published by Packt Publishing
  1. Java 7 Concurrency Cookbook
    1. Java 7 Concurrency Cookbook
    2. Credits
    3. About the Author
    4. About the Reviewers
    5. www.PacktPub.com
      1. Support files, eBooks, discount offers and more
      2. Why Subscribe?
      3. Free Access for Packt account holders
      4. Instant Updates on New Packt Books
    6. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
    7. 1. Thread Management
      1. Introduction
      2. Creating and running a thread
      3. Getting and setting thread information
      4. Interrupting a thread
      5. Controlling the interruption of a thread
      6. Sleeping and resuming a thread
      7. Waiting for the finalization of a thread
      8. Creating and running a daemon thread
      9. Processing uncontrolled exceptions in a thread
      10. Using local thread variables
      11. Grouping threads into a group
      12. Processing uncontrolled exceptions in a group of threads
      13. Creating threads through a factory
    8. 2. Basic Thread Synchronization
      1. Introduction
      2. Synchronizing a method
      3. Arranging independent attributes in synchronized classes
      4. Using conditions in synchronized code
      5. Synchronizing a block of code with a Lock
      6. Synchronizing data access with read/write locks
      7. Modifying Lock fairness
      8. Using multiple conditions in a Lock
    9. 3. Thread Synchronization Utilities
      1. Introduction
      2. Controlling concurrent access to a resource
      3. Controlling concurrent access to multiple copies of a resource
      4. Waiting for multiple concurrent events
      5. Synchronizing tasks in a common point
      6. Running concurrent phased tasks
      7. Controlling phase change in concurrent phased tasks
      8. Changing data between concurrent tasks
    10. 4. Thread Executors
      1. Introduction
      2. Creating a thread executor
      3. Creating a fixed-size thread executor
      4. Executing tasks in an executor that returns a result
      5. Running multiple tasks and processing the first result
      6. Running multiple tasks and processing all the results
      7. Running a task in an executor after a delay
      8. Running a task in an executor periodically
      9. Canceling a task in an executor
      10. Controlling a task finishing in an executor
      11. Separating the launching of tasks and the processing of their results in an executor
      12. Controlling rejected tasks of an executor
    11. 5. Fork/Join Framework
      1. Introduction
      2. Creating a Fork/Join pool
      3. Joining the results of the tasks
      4. Running tasks asynchronously
      5. Throwing exceptions in the tasks
      6. Canceling a task
    12. 6. Concurrent Collections
      1. Introduction
      2. Using non-blocking thread-safe lists
      3. Using blocking thread-safe lists
      4. Using blocking thread-safe lists ordered by priority
      5. Using thread-safe lists with delayed elements
      6. Using thread-safe navigable maps
      7. Generating concurrent random numbers
      8. Using atomic variables
      9. Using atomic arrays
    13. 7. Customizing Concurrency Classes
      1. Introduction
      2. Customizing the ThreadPoolExecutor class
      3. Implementing a priority-based Executor class
      4. Implementing the ThreadFactory interface to generate custom threads
      5. Using our ThreadFactory in an Executor object
      6. Customizing tasks running in a scheduled thread pool
      7. Implementing the ThreadFactory interface to generate custom threads for the Fork/Join framework
      8. Customizing tasks running in the Fork/Join framework
      9. Implementing a custom Lock class
      10. Implementing a transfer Queue based on priorities
      11. Implementing your own atomic object
    14. 8. Testing Concurrent Applications
      1. Introduction
      2. Monitoring a Lock interface
      3. Monitoring a Phaser class
      4. Monitoring an Executor framework
      5. Monitoring a Fork/Join pool
      6. Writing effective log messages
      7. Analyzing concurrent code with FindBugs
      8. Configuring Eclipse for debugging concurrency code
      9. Configuring NetBeans for debugging concurrency code
      10. Testing concurrency code with MultithreadedTC
O'Reilly logo

Controlling a task finishing in an executor

The FutureTask class provides a method called done() that allows you to execute some code after the finalization of a task executed in an executor. It can be used to make some post-process operations, generating a report, sending results by e-mail, or releasing some resources. This method is called internally by the FutureTask class when the execution of the task that this FutureTask object is controlling finishes. The method is called after the result of the task is set and its status is changed to the isDone status, regardless of whether the task has been canceled or finished normally.

By default, this method is empty. You can override the FutureTask class and implement this method to change this behavior. ...

The best content for your career. Discover unlimited learning on demand for around $1/day.