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.

closed as off-topic by durron597, Ixrec, user40980, gnat, ratchet freak Apr 24 '15 at 14:13

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions asking us to recommend a tool, library or favorite off-site resource are off-topic for Programmers as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it." – durron597, Ixrec, Community, gnat, ratchet freak
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I'm keen to see the answers here because I couldn't find any (for Delphi or in general). I ended up using diagrams based on electrical timing diagrams, which worked but were hard for other programmers to understand (samples at brighthub.com/engineering/electrical/articles/60453.aspx). But my code was still fairly brittle - it was hard for other people to make changes without the unit tests failing. And I had to extend DUnit for MT use - I hope JUnit at least does MT testing well. – Мסž Feb 25 '11 at 5:07
  • @moz: UML Sequence Diagram can be useful for documentation and discussion purposes. This diagram is easy to make using hand-drawing, simple applications, or even text editor. – rwong Feb 27 '11 at 3:46
  • @rwong: sequence diagrams are basically simplified timing diagrams. I found that as the code got more complex sequence diagrams stopped being useful well before timing diagrams. – Мסž Feb 27 '11 at 20:52

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.

  • Is there a blog or other starting point? Or a book? – tgkprog Sep 20 '18 at 12:52

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.

  • Hi Link is dead. Is this in Java? Any github or other working link? thanks – tgkprog Sep 20 '18 at 12:51

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)

Not the answer you're looking for? Browse other questions tagged or ask your own question.