Thursday, May 5, 2011

Any suggestions for a program or small project to learn about concurrency in Java?

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.

Any suggestions much appreciated!

From stackoverflow
  • This is not a Complete project but it contains some source codes as well. I think it would be great for get a good understanding about threading.

    Threading in Java

  • If you are an somewhat experienced programmer it might be interesting to create a little server for prescribing to share prices that uses the Fix Protocol. It would need to be able to cope with several clients (and then you get to learn Swing or some web techs) which requires concurrency.

    If you are a beginner I suggest something simpler like a producer thread with a couple of consumer threads and you would get extra points if you can graphically show the process.

  • 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 :-)

    talonx : +1 . IMO this is one of the best ways to learn threading concepts.
    talonx : Oops...'ways' = 'examples'
    jjujuma : Had a quick look and I can see immediately that I don't know how to do that right. So it fits the bill and I shall give it a go - many thanks!
  • A common learning project for concurrency and networking is to write a chat program. It is similar to the FIX server suggestion but you just pass text around.

  • try a sudoku resolver, with various strategies:

    • 3 threads : 1 for rows, 1 for columns and 1 for sub-squares
    • 9 threads : 3 for rows (1 thread each 3 rows), 3 for columns and 3 for sub-squares
    • 27 threads: 9 for rows (1 thread each 1 row), etc
    Chathuranga Chandrasekara : Hmmm... nice idea
    : There is an additional burden of solving a puzzle, which would distract from understanding the principles of concurrent programming.
  • When I read concurrent systems programming at the university, we built a video surveillance system - one master PC that fetched video data from one or more slave PC's with webcams. I remember that project since it really made you grok both efficient network programming, real-time issues and JNI :)

  • I strongly recommend the book Java Concurrency In Practice as a resource while you are working on whichever project you choose.

  • 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.

0 comments:

Post a Comment