Learning Concurrent Programming in Scala - Second Edition.pdf

(29455 KB) Pobierz
Learning Concurrent Programming
in Scala
Second Edition
Learn the art of building intricate, modern, scalable, and
concurrent applications using Scala
Aleksandar Prokopec
BIRMINGHAM - MUMBAI
Learning Concurrent Programming in Scala
Second Edition
Copyright © 2017 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
Second edition: February 2017
Production reference: 1170217
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-78646-689-1
www.packtpub.com
Credits
Author
Aleksandar Prokopec
Reviewers
Vikash Sharma
Dominik Gruntz
Zhen Li
Lukas Rytz
Michel Schinz
Samira Tasharofi
Commissioning Editor
Aaron Lazar
Acquisition Editor
Sonali Vernekar
Content Development Editor
Rohit Kumar Singh
Technical Editor
Pavan Ramchandani
Copy Editor
Safis Editing
Project Coordinator
Vaidehi Sawant
Proofreader
Safis Editing
Indexer
Aishwarya Gangawane
Graphics
Jason Monteiro
Production Coordinator
Shantanu Zagade
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 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 transactions over a mutable store?
Or, maybe the primary purpose of parallel execution is to increase the performance? For
each of these tasks, there is an abstraction that does the job: futures, reactive streams, actors,
transactional memory, or parallel collections.
This brings us to Scala and this book. As there are so many useful concurrency abstractions,
it seems unattractive to hardcode them all in a programming language. The purpose behind
the work on Scala was to make it easy to define high-level abstractions in user code and
libraries. This way, one can define the modules handling the different aspects of concurrent
programming. All of these modules would be built on a low-level core that is provided by
the host system. In retrospect, this approach has worked well. Today, Scala has some of the
most powerful and elegant libraries for concurrent programming. This book will take you
on a tour of the most important ones, explaining the use case for each and the application
patterns.
Zgłoś jeśli naruszono regulamin