aspose file tools*
The moose likes Threads and Synchronization and the fly likes Tips to visualize multithreaded applications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Tips to visualize multithreaded applications" Watch "Tips to visualize multithreaded applications" New topic
Author

Tips to visualize multithreaded applications

java boyinredglass
Greenhorn

Joined: Jun 16, 2012
Posts: 2
Hello internets,

I find it really hard to understand multithreading because I can't find a way to visualize threads in my mind. Do you have simple ways of visualizing the various elements (locks, joins, synchronization, etc.) in a multi-threaded application?
Karol Wojcik
Greenhorn

Joined: Apr 19, 2012
Posts: 17

Well it's quite easy... Check this for locks.
Synchronization... well it's everywhere e.g Airplane can't take off untill all passengers are on board and flight controll give permission. Passengers won't board until a gate is open, flight control won't give permission until the runway is clear- those all are threads needed to be synchronized.
The reader and writer problem... you can't read the file, when some is editing it. So you need to reserve (block) the file for you when you want to work with this file. When you block the file, and forget to free it after work, no one will be allowed do do anything with it... Try to google "semaphore"
Threads can work pararell, e.q you can build a house by yourself (one thread) but you can do it much faster with help of other workers (more threads)



Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2337
    
  28

I've found it helpful to keep swimlanes in my head. The way that many people think closely matches a collaboration diagram. THe conversation in their head goes like this:- "Foo calls Bar, Bar processes and creates thingamajigs. Bar sends the thingamajigs to doo-hickeys...." To me, this is thinking like you are drawing a collabration diagram. The problem is collabration diagram is not good at showing concurrent processes. It's good at showing which components are talking to which other components, but parallelism is lost. You might have an easier time if you think in swimlanes


Having said that I would like to add, the success of a highhly concurrent application lies in it's simplicity. If you are having problems following the code, you might want to rethink the design. Threads shouldn't interact with each other too much
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You might find a UML Activity Diagram or Interaction Overview Diagram useful.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tips to visualize multithreaded applications