I'm aiming to learn about concurrency in Java. Currently my state of knowledge is poor. I'm pretty sure I know what "volatile" means. I sort of know what "synchronized" means. Sometimes. I've never written code that starts threads or manages them. Outside of this issue, I feel confident and at home working in Java.
I'm looking for suggestions for a small project or program which will require understanding concurrency to work correctly and efficiently.
Java Multithreading This is a free course to learn multithreading in Java — you can join it on Udemy, the biggest platform for online courses. This is a nice fundamental course — without being too comprehensive — that tells you everything you need to know in order to read and write concurrent code using Java libraries.
The simplest way to avoid problems with concurrency is to share only immutable data between threads. Immutable data is data which cannot be changed. To make a class immutable define the class and all its fields as final. Also ensure that no reference to fields escape during construction.
A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.
Concurrency is the ability to run several or multi programs or applications in parallel. The backbone of Java concurrency is threads (a lightweight process, which has its own files and stacks and can access the shared data from other threads in the same process).
Write a matrix-multiply algorithm. Parallelize it. Optimize it. See how it scales especially if you have a multi-core machine. That would be a fun project.
If you're really just starting then probably the producer-consumer problem is a good way to start:
http://en.wikipedia.org/wiki/Producer-consumer_problem
Don't read too much because the Wikipedia article also contains a solution to the problem :-)
try a sudoku resolver, with various strategies:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With