Extending the Game - Run Parallel, Run Faster

In this chapter, we will extend the Mastermind game. As it is now, it can guess the secret that was hidden and also hide the pegs. The test code can even do both at the same time. It can play against itself leaving us only with the fun of programming. What it cannot do is make use of all the processors that we have in today's notebooks and servers. The code runs synchronous and utilizes only a single processor core.

We will alter the code extending the guessing algorithm to slice up the guessing into subtasks and execute the code in parallel. During this, we will get acquainted with Java concurrent programming. This will be a huge topic with many subtle corners and caveats lurking in the dark. We will get into those details that are the most important and will form a firm base for further studies whenever you need concurrent programs.

As the outcome of the game is the same as it was, only faster, we have to assess what faster is. To do that, we will utilize a new feature introduced in Java 9: microbenchmarking harness.

In this chapter, we will cover the following topics:

  • The meaning of processes, threads and fibers
  • Multithreading in Java
  • Issues with multithread programming and how to avoid them
  • Locking, synchronization, and blocking queues
  • Microbenchmarking
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.235.23