万本电子书0元读

万本电子书0元读

顶部广告

Mastering Concurrency Programming with Java 8电子书

售       价:¥

2人正在读 | 0人评论 9.8

作       者:Javier Fernández González

出  版  社:Packt Publishing

出版时间:2016-02-29

字       数:629.1万

所属分类: 进口书 > 外文原版书 > 电脑/网络

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Master the principles and techniques of multithreaded programming with the Java 8 Concurrency APIAbout This BookImplement concurrent applications using the Java 8 Concurrency API and its new componentsImprove the performance of your applications or process more data at the same time, taking advantage of all of your resources.Construct real-world examples related to machine learning, data mining, image processing, and client/server environmentsWho This Book Is ForIf you are a competent Java developer with a good understanding of concurrency but have no knowledge of how to effectively implement concurrent programs or use streams to make processes more efficient, then this book is for you.What You Will LearnDesign concurrent applications by converting a sequential algorithm into a concurrent oneDiscover how to avoid all the possible problems you can get in concurrent algorithmsUse the Executor framework to manage concurrent tasks without creating threadsExtend and modify Executors to adapt their behavior to your needsSolve problems using the divide and conquer technique and the Fork/Join frameworkProcess massive data sets with parallel streams and Map/Reduce implementationControl data-race conditions using concurrent data structures and synchronization mechanismsTest and monitor concurrent applicationsIn DetailConcurrency programming allows several large tasks to be divided into smaller sub-tasks, which are further processed as individual tasks that run in parallel. All the sub-tasks are combined together once the required results are achieved; they are then merged to get the final output. The whole process is very complex. This process goes from the design of concurrent algorithms to the testing phase where concurrent applications need extra attention. Java includes a comprehensive API with a lot of ready-to-use components to implement powerful concurrency applications in an easy way, but with a high flexibility to adapt these components to your needs.The book starts with a full de*ion of design principles of concurrent applications and how to parallelize a sequential algorithm. We'll show you how to use all the components of the Java Concurrency API from basics to the most advanced techniques to implement them in powerful concurrency applications in Java.You will be using real-world examples of complex algorithms related to machine learning, data mining, natural language processing, image processing in client / server environments. Next, you will learn how to use the most important components of the Java 8 Concurrency API: the Executor framework to execute multiple tasks in your applications, the phaser class to implement concurrent tasks divided into phases, and the Fork/Join framework to implement concurrent tasks that can be split into smaller problems (using the divide and conquer technique). Toward the end, we will cover the new inclusions in Java 8 API, the Map and Reduce model, and the Map and Collect model. The book will also teach you about the data structures and synchronization utilities to avoid data-race conditions and other critical problems. Finally, the book ends with a detailed de*ion of the tools and techniques that you can use to test a Java concurrent application.Style and approach A complete guide implementing real-world examples with algorithms related to machine learning, data mining, and natural language processing in client/server environments. All the examples are explained in a step-by-step approach.
目录展开

Mastering Concurrency Programming with Java 8

Table of Contents

Mastering Concurrency Programming with Java 8

Credits

About the Author

About the Reviewers

www.PacktPub.com

eBooks, discount offers, and more

Why subscribe?

Preface

What this book covers

What you need for this book

Who this book is for

Conventions

Reader feedback

Customer support

Downloading the example code

Errata

Piracy

eBooks, discount offers, and more

Questions

1. The First Step – Concurrency Design Principles

Basic concurrency concepts

Concurrency versus parallelism

Synchronization

Immutable object

Atomic operations and variables

Shared memory versus message passing

Possible problems in concurrent applications

Data race

Deadlock

Livelock

Resource starvation

Priority inversion

A methodology to design concurrent algorithms

The starting point – a sequential version of the algorithm

Step 1 – analysis

Step 2 – design

Step 3 – implementation

Step 4 – testing

Step 5 – tuning

Conclusion

Java concurrency API

Basic concurrency classes

Synchronization mechanisms

Executors

The Fork/Join framework

Parallel streams

Concurrent data structures

Concurrency design patterns

Signaling

Rendezvous

Mutex

Multiplex

Barrier

Double-checked locking

Read-write lock

Thread pool

Thread local storage

The Java memory model

Tips and tricks to design concurrent algorithms

Identify the correct independent tasks

Implement concurrency at the highest possible level

Take scalability into account

Use thread-safe APIs

Never assume an execution order

Prefer local thread variables over static and shared when possible

Find the more easily parallelizable version of the algorithm

Using immutable objects when possible

Avoiding deadlocks by ordering the locks

Using atomic variables instead of synchronization

Holding locks for as short a time as possible

Taking precautions using lazy initialization

Avoiding the use of blocking operations inside a critical section

Summary

2. Managing Lots of Threads – Executors

An introduction to executors

Basic characteristics of executors

Basic components of the executor framework

First example – the k-nearest neighbors algorithm

K-nearest neighbors – serial version

K-nearest neighbors – a fine-grained concurrent version

K-nearest neighbors – a coarse-grained concurrent version

Comparing the solutions

The second example – concurrency in a client/server environment

Client/server – serial version

The DAO part

The command part

The server part

Client/server – parallel version

The server part

The command part

Extra components of the concurrent server

The status command

The cache system

The log system

Comparing the two solutions

Other methods of interest

Summary

3. Getting the Maximum from Executors

Advanced characteristics of executors

Cancellation of tasks

Scheduling the execution of tasks

Overriding the executor methods

Changing some initialization parameters

The first example – an advanced server application

The ServerExecutor class

The statistics object

The rejected task controller

The executor tasks

The executor

The command classes

The ConcurrentCommand class

Concrete commands

The server part

The ConcurrentServer class

The RequestTask class

The client part

The second example – executing periodic tasks

The common parts

The basic reader

The advanced reader

Additional information about executors

Summary

4. Getting Data from the Tasks – The Callable and Future Interfaces

Introducing the Callable and Future interfaces

The Callable interface

The Future interface

First example – a best-matching algorithm for words

The common classes

A best-matching algorithm – the serial version

The BestMatchingSerialCalculation class

The BestMachingSerialMain class

A best-matching algorithm – the first concurrent version

The BestMatchingBasicTask class

The BestMatchingBasicConcurrentCalculation class

A best-matching algorithm – the second concurrent version

The word exists algorithm – a serial version

The ExistSerialCalculation class

The ExistSerialMain class

The word exists algorithm – the concurrent version

The ExistBasicTasks class

The ExistBasicConcurrentCalculation class

The ExistBasicConcurrentMain class

Comparing the solutions

Best-matching algorithms

Exist algorithms

The second example – creating an inverted index for a collection of documents

Common classes

The Document class

The DocumentParser class

The serial version

The first concurrent version – a task per document

The IndexingTask class

The InvertedIndexTask class

The ConcurrentIndexing class

The second concurrent version – multiple documents per task

The MultipleIndexingTask class

The MultipleInvertedIndexTask class

The MultipleConcurrentIndexing class

Comparing the solutions

Other methods of interest

Summary

5. Running Tasks Divided into Phases – The Phaser Class

An introduction to the Phaser class

Registration and deregistration of participants

Synchronizing phase changes

Other functionalities

First example – a keyword extraction algorithm

Common classes

The Word class

The Keyword class

The Document class

The DocumentParser class

The serial version

The concurrent version

The KeywordExtractionTask class

The ConcurrentKeywordExtraction class

Comparing the two solutions

The second example – a genetic algorithm

Common classes

The Individual class

The GeneticOperators class

The serial version

The SerialGeneticAlgorithm class

The SerialMain class

The concurrent version

The SharedData class

The GeneticPhaser class

The ConcurrentGeneticTask class

The ConcurrentGeneticAlgorithm class

The ConcurrentMain class

Comparing the two solutions

The Lau15 dataset

The Kn57 dataset

Conclusions

Summary

6. Optimizing Divide and Conquer Solutions – The Fork/Join Framework

An introduction to the Fork/Join framework

Basic characteristics of the Fork/Join framework

Limitations of the Fork/Join framework

Components of the Fork/Join framework

The first example – the k-means clustering algorithm

The common classes

The VocabularyLoader class

The Word, Document, and DocumentLoader classes

The DistanceMeasurer class

The DocumentCluster class

The serial version

The SerialKMeans class

The concurrent version

Two tasks for the Fork/Join framework – AssignmentTask and UpdateTask

The ConcurrentKMeans class

The ConcurrentMain class

Comparing the solutions

The second example – a data filtering algorithm

Common parts

The serial version

The SerialSearch class

The SerialMain class

The concurrent version

The TaskManager class

The IndividualTask class

The ListTask class

The ConcurrentSearch class

The ConcurrentMain class

Comparing the two versions

The third example – the merge sort algorithm

Shared classes

The serial version

The SerialMergeSort class

The SerialMetaData class

The concurrent version

The MergeSortTask class

The ConcurrentMergeSort class

The ConcurrentMetaData class

Comparing the two versions

Other methods of the Fork/Join framework

Summary

7. Processing Massive Datasets with Parallel Streams – The Map and Reduce Model

An introduction to streams

Basic characteristics of streams

Sections of a stream

Sources of a stream

Intermediate operations

Terminal operations

MapReduce versus MapCollect

The first example – a numerical summarization application

The concurrent version

The ConcurrentDataLoader class

The ConcurrentStatistics class

Job information from subscribers

Age data from subscribers

Marital data from subscribers

Campaign data from nonsubscribers

Multiple data filter

Duration data from nonsubscribers

People aged between 25 and 50

The ConcurrentMain class

The serial version

Comparing the two versions

The second example – an information retrieval search tool

An introduction to the reduction operation

The first approach – full document query

The basicMapper() method

The Token class

The QueryResult class

The second approach – reduced document query

The limitedMapper() method

The third approach – generating an HTML file with the results

The ContentMapper class

The fourth approach – preloading the inverted index

The ConcurrentFileLoader class

The fifth approach – using our own executor

Getting data from the inverted index – the ConcurrentData class

Getting the number of words in a file

Getting the average tfxidf value in a file

Getting the maximum and minimum tfxidf values in the index

The ConcurrentMain class

The serial version

Comparing the solutions

Summary

8. Processing Massive Datasets with Parallel Streams – The Map and Collect Model

Using streams to collect data

The collect() method

The first example – searching data without an index

Basic classes

The Product class

The Review class

The ProductLoader class

The first approach – basic search

The ConcurrentStringAccumulator class

The second approach – advanced search

The ConcurrentObjectAccumulator class

A serial implementation of the example

Comparing the implementations

The second example – a recommendation system

Common classes

The ProductReview class

The ProductRecommendation class

The recommendation system – the main class

The ConcurrentLoaderAccumulator class

The serial version

Comparing the two versions

The third example – common contacts in a social network

Base classes

The Person class

The PersonPair class

The DataLoader class

The concurrent version

The CommonPersonMapper class

The ConcurrentSocialNetwork class

The ConcurrentMain class

The serial version

Comparing the two versions

Summary

9. Diving into Concurrent Data Structures and Synchronization Utilities

Concurrent data structures

Blocking and non-blocking data structures

Interfaces

BlockingQueue

BlockingDeque

ConcurrentMap

TransferQueue

Classes

LinkedBlockingQueue

ConcurrentLinkedQueue

LinkedBlockingDeque

ConcurrentLinkedDeque

ArrayBlockingQueue

DelayQueue

LinkedTransferQueue

PriorityBlockingQueue

ConcurrentHashMap

Using the new features

First example with ConcurrentHashMap

The forEach() method

The search() method

The reduce() method

The compute() method

Another example with ConcurrentHashMap

An example with the ConcurrentLinkedDeque class

The removeIf() method

The spliterator() method

Atomic variables

Synchronization mechanisms

The CommonTask class

The Lock interface

The Semaphore class

The CountDownLatch class

The CyclicBarrier class

The CompletableFuture class

Using the CompletableFuture class

Auxiliary tasks

The main() method

Summary

10. Integration of Fragments and Implementation of Alternatives

Big-block synchronization mechanisms

An example of a document clustering application

The four systems of k-means clustering

The Reader system

The Indexer system

The Mapper system

The Clustering system

The main class of the document clustering application

Testing our document clustering application

Implementation of alternatives with concurrent programming

The k-nearest neighbors' algorithm

Building an inverted index of a collection of documents

A best-matching algorithm for words

A genetic algorithm

A keyword extraction algorithm

A k-means clustering algorithm

A filtering data algorithm

Searching an inverted index

A numeric summarization algorithm

A search algorithm without indexing

A recommendation system using the Map and Collect model

Summary

11. Testing and Monitoring Concurrent Applications

Monitoring concurrency objects

Monitoring a thread

Monitoring a lock

Monitoring an executor

Monitoring the Fork/Join framework

Monitoring a Phaser

Monitoring a stream

Monitoring concurrency applications

The Overview tab

The Monitor tab

The Threads tab

The Sampler tab

The Profiler tab

Testing concurrency applications

Testing concurrent applications with MultithreadedTC

Testing concurrent applications with Java Pathfinder

Installing Java Pathfinder

Running Java Pathfinder

Summary

Index

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部