Since I’m getting back on programming, I’m currently re-skilling myself on this duty. Having not programmed Java in a while, I’ve found myself on trouble on this simple topic: Java concurrency and threads. I will insert on the blog some “quick tutorials” about various subjects. I’ve found that programmers sometimes need a fast solution on a given problem. They could surely get it by looking at the API’s and so on, but it costs valuable time. So I will go straight to the problem.

  • Problem: I need to do a fixed job on some data in a parallel fashion.
  • Solution: using a multi-threaded model, I have two classes Controller and Worker. Worker is essentially a thread that does the fixed job and reports the data to the Controller
  • Main issues: is it better to “extends Thread” or to” implements Runnable“? How to accessing shared variables concurrently and avoid race conditions? How to pass data from Worker to Controller?

Read it all..