Are there any canonical sources for learning how to structure multi-threaded programs? Even with all the concurrency utility classes that Java provides I'm having a hard time properly structuring multi-threaded programs. Whenever threads are involved my code becomes very brittle, any little change can potentially break the program because the code that jumps back and forth between the threads tends to be very convoluted.
|
|
If you haven't already, I highly recommend reading "Java Concurrency in Practice". While it doesn't directly solves your problem, it'll certainly provide helpful background on Java Concurrency, and you'll be able to better structure your programs. |
|||
|
|
|
Look at the GNU/Linux shell pipelines for hints as to how to structure a multi-threaded program. The pipeline concept of a loop which does reading-working-writing is proven, established, well understood and easy to implement in threads instead of processes. (I used to write software for radars and sonars, where "real time" actually meant real time.) Follow the pipeline design pattern. It's how good, robust software is written. |
|||
|
|
|
There's a monogram called Structured Development of Parallel Programs, by Susanna Pelagatti. Despite being old (1998 - and hence out of print) the way you structure parallel programs hasn't actually changed much, just the tools available for scheduling and manipulated work units have. The methodology described in the book is still pretty useful. |
|||
|
|
|
Study ACE framework - it's a great way to learn design patterns and even grab reusable components for concurrent programming and communication. It addresses many areas of concern for multithreaded programming: organizing and communicating between your threads, synchronizing data access, and performing IO. And it take good care of performance issues too. |
|||
|
|
|
I would suggest "Pattern-Oriented Software Architecture Volume 2: Patterns for Concurrent and Networked Objects". |
|||
|
|
|
Check out erlang, it does concurrency quite well, but takes a very different approach to it, by being a functional language with a shared nothing model it removes the need for locks (mostly) |
|||
|
|
