Learning Concurrent Programming in Scala

By Aleksandar Prokopec

Learn the paintings of establishing tricky, sleek, scalable concurrent functions utilizing Scala

About This Book

  • Design and enforce scalable and easy-to-understand concurrent applications
  • Make the main of Scala by means of figuring out its philosophy and harnessing the ability of multicores
  • Get conversant in state-of-the-art applied sciences within the box of concurrency, with a specific emphasis on sensible, real-world applications
  • Step-by-step instructional consultant, that's filled with pragmatic examples

Who This publication Is For

This e-book is a must have instructional for software program builders aiming to write down concurrent courses in Scala, or expand their present wisdom of concurrency.

This e-book is meant for Scala programmers that experience no earlier wisdom approximately concurrent programming, in addition to these trying to develop their latest wisdom approximately concurrency. uncomplicated wisdom of the Scala programming language may be important. Readers with an outstanding wisdom in one other programming language, comparable to Java, should still locate this ebook simply accessible.

What you'll Learn

  • Get to grips with the basics of concurrent programming on smooth multiprocessor structures, with a selected specialize in the JVM concurrency model
  • Build high-performance concurrent structures from uncomplicated, low-level concurrency primitives
  • Express asynchrony in concurrent computations with futures and promises
  • Seamlessly speed up sequential courses by utilizing data-parallel collections
  • Implement reactive and event-based courses declaratively with Rx-style occasion streams
  • Design secure, scalable, and easy-to-comprehend in-memory transactional facts models
  • Transparently create dispensed purposes that scale throughout a number of machines
  • Choose the proper concurrency abstraction and combine varied concurrency frameworks jointly in huge applications

In Detail

This ebook provides you with an perception into the simplest practices essential to construct concurrent courses in Scala utilizing sleek, high-level concurrency libraries. It begins by way of introducing you to the principles of concurrent programming at the JVM, outlining the fundamentals of the Java reminiscence version, after which indicates many of the vintage development blocks of concurrency, reminiscent of the atomic variables, thread swimming pools, and concurrent info constructions, in addition to the caveats of conventional concurrency. It then walks you thru varied high-level concurrency abstractions, every one adapted towards a particular type of programming initiatives. ultimately, the e-book provides an outline of while to exploit which concurrency library and demonstrates how all of them paintings together.

Show description

Quick preview of Learning Concurrent Programming in Scala PDF

Best Programming books

Joe Celko's SQL for Smarties: Advanced SQL Programming Third Edition (The Morgan Kaufmann Series in Data Management Systems)

SQL for Smarties was once hailed because the first booklet committed explicitly to the complex recommendations had to remodel an skilled SQL programmer into a professional. Now, 10 years later and within the 3rd variation, this vintage nonetheless reigns excellent because the booklet written by means of an SQL grasp that teaches destiny SQL masters.

Designing Audio Effect Plug-Ins in C++: With Digital Audio Signal Processing Theory

Not only one other theory-heavy electronic sign processing ebook, nor one other boring build-a-generic-database programming ebook, Designing Audio impact Plug-Ins in C++ provides every little thing you every thing you must comprehend to do exactly that, together with absolutely labored, downloadable code for dozens audio impact plug-ins and virtually provided algorithms.

Effective C++: 55 Specific Ways to Improve Your Programs and Designs (3rd Edition)

“Every C++ expert wishes a duplicate of powerful C++. it truly is an absolute must-read for a person deliberating doing severe C++ improvement. If you’ve by no means learn potent C++ and also you imagine you recognize every little thing approximately C++, reassess. ”— Steve Schirripa, software program Engineer, Google “C++ and the C++ neighborhood have grown up within the final fifteen years, and the 3rd variation of potent C++ displays this.

Cocoa Design Patterns

“Next time a few child exhibits up at my door requesting a code assessment, this is often the ebook that i'm going to throw at him. ”   –Aaron Hillegass, founding father of significant Nerd Ranch, Inc. , and writer of Cocoa Programming for Mac OS X   Unlocking the secrets and techniques of Cocoa and Its Object-Oriented Frameworks   Mac and iPhone builders are frequently beaten by way of the breadth and class of the Cocoa frameworks.

Additional info for Learning Concurrent Programming in Scala

Show sample text content

Different inherently sequential operations comprise foldRight, reduceLeft, reduceRight, reduceLeftOption, reduceRightOption, scanLeft, scanRight, and techniques that produce non-parallelizable collections similar to toList. negative effects in parallel operations As their identify implies, parallel collections execute on a number of threads simultaneously. we've got already discovered in bankruptcy 2, Concurrency at the JVM and the Java reminiscence version, that a number of threads can't appropriately adjust shared reminiscence destinations with out using synchronization. Assigning to a mutable variable from a parallel assortment operation will be tempting, however it is sort of definitely flawed. this can be most sensible illustrated via the subsequent instance during which we build units, a and b, the place b is the subset of the weather in a, after which use a complete mutable variable to count number the scale of the intersection: item ParSideEffectsIncorrect extends App { def intersectionSize(a: GenSet[Int], b: GenSet[Int]): Int = { var overall = zero [ 151 ] Data-Parallel Collections for (x <- a) if (b includes x) overall += 1 overall } val a = (0 until eventually 1000). toSet val b = (0 till one thousand by means of 4). toSet val seqres = intersectionSize(a, b) val parres = intersectionSize(a. par, b. par) log(s"Sequential consequence - $seqres") log(s"Parallel consequence - $parres") } rather than returning 250, the parallel model nondeterministically returns a variety of mistaken effects. observe that you simply may need to alter the sizes of the units a and b to witness this: run-main-32: Sequential end result - 250 run-main-32: Parallel outcome - 244 to make sure that the parallel model returns the right kind effects, we will be able to use an atomic variable and its incrementAndGet procedure. even if, this results in a similar scalability difficulties we had prior to. a greater replacement is to take advantage of the parallel count number strategy: a. count(x => b comprises x) If the volume of labor carried out in line with aspect is low and the fits are widespread, the parallel count number strategy will lead to higher functionality than the foreach procedure with an atomic variable. to prevent the necessity for synchronization and make sure greater scalability, prefer declarative-style parallel operations rather than the unwanted side effects in parallel for loops. equally, we needs to make sure that the reminiscence destinations learn through a parallel operation are protected against concurrent writes. within the final instance, the b set shouldn't be at the same time mutated through a few thread whereas the parallel operation is executing— this results in an identical flawed effects as utilizing mutable variables from in the parallel operation. [ 152 ] Chapter five Nondeterministic parallel operations In bankruptcy 2, Concurrency at the JVM and the Java reminiscence version, we observed that multithreaded courses should be nondeterministic; given an identical inputs, they could produce assorted outputs looking on the execution time table. The locate assortment operation returns a component matching a given predicate. The parallel locate operation returns whichever aspect was once discovered first by means of a few processor. within the following instance, we use locate to look the HTML specification for occurrences of the TEXTAREA string; operating the instance a number of occasions provides diverse effects, as the TEXTAREA string happens in lots of diverse areas within the HTML specification: item ParNonDeterministicOperation extends App { ParHtmlSearch.

Download PDF sample

Rated 4.47 of 5 – based on 41 votes