Learning Concurrent Programming in Scala
eBook - ePub

Learning Concurrent Programming in Scala

Aleksandar Prokopec

  1. 366 pages
  2. English
  3. ePUB (adapté aux mobiles)
  4. Disponible sur iOS et Android
eBook - ePub

Learning Concurrent Programming in Scala

Aleksandar Prokopec

DĂ©tails du livre
Aperçu du livre
Table des matiĂšres
Citations

À propos de ce livre

This book will give you an insight into the best practices necessary to build concurrent programs in Scala using modern, high-level concurrency libraries. It starts by introducing you to the foundations of concurrent programming on the JVM, outlining the basics of the Java Memory Model, and then shows some of the classic building blocks of concurrency, such as the atomic variables, thread pools, and concurrent data structures, along with the caveats of traditional concurrency. It then walks you through different high-level concurrency abstractions, each tailored toward a specific class of programming tasks. Finally, the book presents an overview of when to use which concurrency library and demonstrates how they all work together.

Foire aux questions

Comment puis-je résilier mon abonnement ?
Il vous suffit de vous rendre dans la section compte dans paramĂštres et de cliquer sur « RĂ©silier l’abonnement ». C’est aussi simple que cela ! Une fois que vous aurez rĂ©siliĂ© votre abonnement, il restera actif pour le reste de la pĂ©riode pour laquelle vous avez payĂ©. DĂ©couvrez-en plus ici.
Puis-je / comment puis-je télécharger des livres ?
Pour le moment, tous nos livres en format ePub adaptĂ©s aux mobiles peuvent ĂȘtre tĂ©lĂ©chargĂ©s via l’application. La plupart de nos PDF sont Ă©galement disponibles en tĂ©lĂ©chargement et les autres seront tĂ©lĂ©chargeables trĂšs prochainement. DĂ©couvrez-en plus ici.
Quelle est la différence entre les formules tarifaires ?
Les deux abonnements vous donnent un accĂšs complet Ă  la bibliothĂšque et Ă  toutes les fonctionnalitĂ©s de Perlego. Les seules diffĂ©rences sont les tarifs ainsi que la pĂ©riode d’abonnement : avec l’abonnement annuel, vous Ă©conomiserez environ 30 % par rapport Ă  12 mois d’abonnement mensuel.
Qu’est-ce que Perlego ?
Nous sommes un service d’abonnement Ă  des ouvrages universitaires en ligne, oĂč vous pouvez accĂ©der Ă  toute une bibliothĂšque pour un prix infĂ©rieur Ă  celui d’un seul livre par mois. Avec plus d’un million de livres sur plus de 1 000 sujets, nous avons ce qu’il vous faut ! DĂ©couvrez-en plus ici.
Prenez-vous en charge la synthÚse vocale ?
Recherchez le symbole Écouter sur votre prochain livre pour voir si vous pouvez l’écouter. L’outil Écouter lit le texte Ă  haute voix pour vous, en surlignant le passage qui est en cours de lecture. Vous pouvez le mettre sur pause, l’accĂ©lĂ©rer ou le ralentir. DĂ©couvrez-en plus ici.
Est-ce que Learning Concurrent Programming in Scala est un PDF/ePUB en ligne ?
Oui, vous pouvez accĂ©der Ă  Learning Concurrent Programming in Scala par Aleksandar Prokopec en format PDF et/ou ePUB ainsi qu’à d’autres livres populaires dans Informatica et Sviluppo web. Nous disposons de plus d’un million d’ouvrages Ă  dĂ©couvrir dans notre catalogue.

Informations

Année
2014
ISBN
9781783281411
Édition
1
Sous-sujet
Sviluppo web

Learning Concurrent Programming in Scala


Table of Contents

Learning Concurrent Programming in Scala
Credits
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
How this book is organized
What this book covers
What you need for this book
Installing the JDK
Installing and using SBT
Using Eclipse, IntelliJ IDEA, or another IDE
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Introduction
Concurrent programming
A brief overview of traditional concurrency
Modern concurrency paradigms
The advantages of Scala
Preliminaries
Execution of a Scala program
A Scala primer
Summary
Exercises
2. Concurrency on the JVM and the Java Memory Model
Processes and Threads
Creating and starting threads
Atomic execution
Reordering
Monitors and synchronization
Deadlocks
Guarded blocks
Interrupting threads and the graceful shutdown
Volatile variables
The Java Memory Model
Immutable objects and final fields
Summary
Exercises
3. Traditional Building Blocks of Concurrency
The Executor and ExecutionContext objects
Atomic primitives
Atomic variables
Lock-free programming
Implementing locks explicitly
The ABA problem
Lazy values
Concurrent collections
Concurrent queues
Concurrent sets and maps
Concurrent traversals
Creating and handling processes
Summary
Exercises
4. Asynchronous Programming with Futures and Promises
Futures
Starting future computations
Future callbacks
Futures and exceptions
Using the Try type
Fatal exceptions
Functional composition on futures
Promises
Converting callback-based APIs
Extending the future API
Cancellation of asynchronous computations
Futures and blocking
Awaiting futures
Blocking in asynchronous computations
The Scala Async library
Alternative Future frameworks
Summary
Exercises
5. Data-Parallel Collections
Scala collections in a nutshell
Using parallel collections
Parallel collection class hierarchy
Configuring the parallelism level
Measuring the performance on the JVM
Caveats of parallel collections
Non-parallelizable collections
Non-parallelizable operations
Side effects in parallel operations
Nondeterministic parallel operations
Commutative and associative operators
Using parallel and concurrent collections together
Weakly consistent iterators
Implementing custom parallel collections
Splitters
Combiners
Alternative data-parallel frameworks
Collections hierarchy in ScalaBlitz
Summary
Exercises
6. Concurrent Programming with Reactive Extensions
Creating Observable objects
Observables and exceptions
The Observable contract
Implementing custom Observable objects
Creating Observables from futures
Subscriptions
Composing Observable objects
Nested observables
Failure handling in observables
Rx schedulers
Using custom schedulers for UI applications
Subjects and top-down reactive programming
Summary
Exercises
7. Software Transactional Memory
The trouble with atomic variables
Using Software Transactional Memory
Transactional references
Using the atomic statement
Composing transactions
The interaction between transactions and side effects
Single-operation transactions
Nesting transactions
Transactions and exceptions
Retrying transactions
Retrying with timeouts
Transactional collections
Transaction-local variables
Transactional arrays
Transactional maps
Summary
Exercises
8. Actors
Working with actors
Creating actor systems and actors
Managing unhandled messages
Actor behavior and state
Akka actor hierarchy
Identifying actors
The actor life cycle
Communication between actors
The ask pattern
The forward pattern
Stopping actors
Actor supervision
Remote actors
Summary
Exercises
9. Concurrency in Practice
Choosing the right tools for the job
Putting it all together – a remote file browser
Modeling the filesystem
The server interface
Client navigation API
The client user interface
Implementing the client logic
Improving the remote file browser
Debugging concurrent programs
Deadlocks and lack of progress
Debugging incorrect program outputs
Performance debugging
Summary
Exercises
Index

Learning Concurrent Programming in Scala

Copyright © 2014 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: November 2014
Production reference: 1211114
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78328-141-1
www.packtpub.com

Credits

Author
Aleksandar Prokopec
Reviewers
Dominik Gruntz
Vladimir Kostyukov
Zhen Li
Lukas Rytz
Michel Schinz
Samira Tasharofi
Commissioning Editor
Kevin Colaco
Acquisition Editor
Kevin Colaco
Content Development Editor
Vaibhav Pawar
Technical Editor
Sebastian Rodrigues
Copy Editors
Rashmi Sawant
Stuti Srivastava
Project Coordinator
Kranti Berde
Proofreaders
Mario Cecere
Martin Diver
Ameesha Green
Indexer
Tejal Soni
Production Coordinator
Aparna Bhagat
Cover Work
Aparna Bhagat

Foreword

Concurrent and parallel programming have progressed from niche disciplines, of interest only to kernel programming and high-performance computing, to something that every competent programmer must know. As parallel and distributed computing systems are now the norm, most applications are concurrent, be it for increasing the performance or for handling asynchronous events.
So far, most developers are unprepared to deal with this revolution. Maybe they have learned the traditional concurrency model, which is based on threads and locks, in school, but this model has become inadequate for dealing with massive concurrency in a reliable manner and with acceptable productivity. Indeed, threads and locks are hard to use and harder to get right. To make progress, one needs to use concurrency abstractions that are at a higher level and composable.
15 years ago, I worked on a predecessor of Scala: "Funnel" was an experimental programming language that had a concurrent semantics at its core. All the programming concepts were explained in this language as syntactic sugar on top of "functional nets", an object-oriented variant of "join calculus". Even though join calculus is a beautiful theory, we realized after some experimentation that the concurrency problem is more multifaceted than what can be comfortably expressed in a single formalism. There is no silver bullet for all concurrency issues; the right solution depends on what one needs to achieve. Do you want to define asynchronous computations that react to events or streams of values? Or have autonomous, isolated entities communicating via messages? Or define trans...

Table des matiĂšres