SynchronizationExample -- comparing unsynchronized and synchronized behaviors.

This applet runs a simple loop that would be quite robust in a single-threaded world. But by running the same loop in multiple threads, you render the loop unsafe. Adding synchronization gives you back safety, but with a significant performance penalty.

Experiment:



The source.