Cannot get my head around concurrency in java, tried reading from the recommended books [closed] Cannot get my head around concurrency in java, tried reading from the recommended books [closed] multithreading multithreading

Cannot get my head around concurrency in java, tried reading from the recommended books [closed]


but am also fairly new to java programming

Leave the concurrency book aside for a few months and go ahead with reading a basic Java/SCJP book and practicing basic Java a lot. Create so now and then a Thread or Runnable as per the book's instructions. Play around with it for some months until you get a good grasp on it. Then continue with the concurrency book.

Learn walking before running, else you're crawling instead of running.


This sounds like you will soon be tested (class? certification?) "on Java concurrency". You have not experienced the cycle of running into a problem naturally, thinking about how to solve it, and turning to concurrency for a solution. If this is the case...

(1) Don't blame your brain. Rather, take a step back and start thinking about problems that interest you. Write them down. Internet applications are a good place to start. For example-- writing some sort of Internet server that can handle multiple connections from different users, like a game server. Or, a stock trading program that has to handle your robot's orders at the same time as processing information from the broker.

(2) Think concurrency. Now that you have a problem that interests you, and thinking of concurrency simply as multi-tasking, draw a diagram of actors/programs with arrows representing how they need to communicate with each other. Sketch out a dummy-skeleton code. You're not actually going to write a game server; but you can make a simple skeleton class library with simple, empty member functions like connectToGame(){}

(3) Now you're ready. Run a hello-world thread example or two. Flip through your books or browse the Javadocs and see the different concurrent structures that are available. Think about which ones you might apply to your problem. Don't worry about making the "right choice". You will soon find out if you've got something that works.

(4) Embrace trial and error. There is another word for it: learning!

Now, after you get some experience doing this, you'll be able to pick up a Java concurrency book and read about someone else's problem.

Hang in there and don't give up.