Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors

By Venkat Subramaniam

More than ever, studying to application concurrency is important to making quicker, responsive purposes. fast and cheap multicore is using the call for for high-performing purposes, and you may leverage the Java platform to convey those purposes to life.

Concurrency at the Java platform has advanced, from the synchronization version of JDK to software program transactional reminiscence (STM) and actor-based concurrency. This publication is the 1st to teach you some of these concurrency kinds so that you can evaluate and select what works top in your functions. You'll research the advantages of each one of those versions, whilst and the way to exploit them, and what their barriers are.

via hands-on workouts, you'll the best way to stay away from shared mutable country and tips on how to write sturdy, dependent, particular synchronization-free courses so that you can create effortless and secure concurrent purposes. The options you study during this publication will take you from dreading concurrency to gaining knowledge of and having fun with it. better of all, you could paintings with Java or a JVM language of your selection - Clojure, JRuby, Groovy, or Scala - to harvest the becoming strength of multicore hardware.

when you are a Java programmer, you'd want JDK 1.5 or later and the Akka 1.0 library. moreover, in the event you application in Scala, Clojure, Groovy or JRuby you'd want the most recent model of your chosen language. Groovy programmers also will desire GPars.

Show description

Preview of Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors PDF

Best Java books

Mastering Lambdas: Java Programming in a Multicore World (Oracle Press)

The Definitive advisor to Lambda Expressions gaining knowledge of Lambdas: Java Programming in a Multicore international describes how the lambda-related gains of Java SE eight will permit Java to satisfy the demanding situations of next-generation parallel architectures. The booklet explains tips on how to write lambdas, and the way to take advantage of them in streams and in assortment processing, offering code examples all through.

Mastering JavaFX 8 Controls (Oracle Press)

Layout and set up High-Performance JavaFX Controls bring state of the art functions with visually attractive UIs. learning JavaFX eight Controls presents transparent directions, designated examples, and ready-to-use code samples. how one can paintings with the most recent JavaFX APIs, configure UI elements, immediately generate FXML, construct state-of-the-art controls, and successfully observe CSS styling.

Data Abstraction and Problem Solving with Java: Walls and Mirrors (3rd Edition)

The 3rd variation of information Abstraction and challenge fixing with Java: partitions and Mirrors employs the analogies of partitions (data abstraction) and Mirrors (recursion) to educate Java programming layout ideas, in a fashion that starting scholars locate available. The booklet has a student-friendly pedagogical procedure that conscientiously debts for the strengths and weaknesses of the Java language.

Java Software Solutions: Foundations of Program Design (7th Edition)

Java software program recommendations teaches a beginning of programming suggestions to foster well-designed object-oriented software program. Heralded for its integration of small and big sensible examples, this world wide best-selling textual content emphasizes development sturdy problem-solving and layout abilities to put in writing top quality courses.

Extra info for Programming Concurrency on the JVM: Mastering Synchronization, STM, and Actors

Show sample text content

It may possibly ensue whilst a thread waits for enter from a consumer, for a few exterior occasion to take place, or for one more thread to liberate a lock. The thread will remain alive whereas it waits, doing not anything. we will hinder hunger by way of putting a timeout. layout the answer in this type of means that the thread waits for just a finite period of time. If the enter doesn't arrive, the development doesn't occur, or the thread doesn't achieve the lock inside that point, then the thread bails out and takes another motion to make development. We run into impasse if or extra threads are ready on one another for a few motion or source. putting a timeout, regrettably, won't aid steer clear of the impasse. It’s attainable that every thread will quit its assets, in basic terms to copy its steps, which leads back right into a deadlock—see “The eating Philosophers challenge” in Appendix 2, net assets, on web page 255. instruments obtain from Wow! publication file erratum • speak about 6 • bankruptcy 1. the ability and Perils of Concurrency reminiscent of JConsole might help realize deadlocks, and we will be able to hinder impasse via buying assets in a selected order. a greater replacement, within the first position, will be to prevent particular locks and the mutable country that is going with them. We’ll see tips on how to do this later within the publication. Race stipulations If threads compete to take advantage of a similar source or facts, we have now a race situation. A race doesn’t simply ensue whilst threads regulate info. it may possibly occur even if one is altering facts whereas the opposite is attempting to learn it. Race stipulations can render a program’s habit unpredictable, produce flawed execution, and yield mistaken effects. forces can result in race conditions—the Just-in-Time (JIT) compiler optimization and the Java reminiscence version. For a superb treatise concerning Java reminiscence version and the way it impacts concurrency, confer with Brian Goetz’s seminal e-book Java Concurrency in perform [Goe06]. Let’s have a look at a reasonably easy instance that illustrates the matter. within the following code, the most thread creates a thread, sleeps for 2 seconds, and units the flag performed to real. The thread created, meanwhile, loops over the flag, so long as it’s fake. Let’s bring together and run the code and notice what occurs: obtain introduction/RaceCondition. java public classification RaceCondition { deepest static boolean performed; public static void main(final String[] args) throws InterruptedException{ new Thread( new Runnable() { public void run() { int i = zero; while(! performed) { i++; } approach. out. println("Done! "); } } ). start(); method. out. println("OS: " + method. getProperty("os. name")); Thread. sleep(2000); performed = real; process. out. println("flag performed set to true"); } } obtain from Wow! booklet document erratum • speak about The Perils of Concurrency • 7 If we run that little application on home windows 7 (32-bit model) utilizing the command java RaceCondition, we’ll realize anything like this (the order of output may possibly range on each one run): OS: home windows 7 flag performed set to actual performed!

Download PDF sample

Rated 4.03 of 5 – based on 29 votes