I have been researching into when data is being accessed or shared by multiple threads within Java. And looking into the problems such as:

  • Thread Interference
  • Memory Consistency
  • Deadlock
  • Starvation

From this, solutions to solve these problems.

So far all I seem find to fixing these problems is by using a synchronizing method. Are there other alternatives to using a synchronizing method?

I have found most of this information from the sun Java tutorial. Any recommendations on further reading?

4 Answers 4


There are many techniques which don't require explicit synchronisation.

For example, if you keep all data local to each thread and communicate only via passing messages, then the synchronisation is performed implicitly by sending and awaiting messages.

Message passing systems have the advantage that they scale very well, since they don't require a unified memory architecture and there are formal techniques for detecting and preventing deadlock, for instance Communicating Sequential Processes (CSP) helps you formally reason about such systems.

Another option is the use of immutable data sets. If nothing can change, you never need to synchronise, because there will never be any chance that more than one thread will try to write at once.

You can even combine them, if one process creates immutable shared memory data sets, it can use messages to pass pointers to consumers of that data.

Finally, you could think in terms of higher levels of abstractions. Tie your processes together by BlockingQueue from java.util.concurrent and you don't need to think about the actual implementation of the Queue, you just produce them in with one process and consume them in another.

There is even a lower level of abstraction than synchronized, using primitives such as Semaphor.

In all, it is a rich and deep area to study, and understanding the pros and cons of each technique has the potential to make you a better programmer.

  • I'll add to this that if you are continuing to use Java's core libraries, then please use java.util.concurrent based techniques and data structures as outlined in Brian Goetz's "Java Concurrency in Practice" title. Using synchronized keyword in a majority of cases is no longer recommended Commented Feb 29, 2012 at 22:41

I would recommend looking into using immutable objects for shared data. As much as possible, try to restrict access to mutated data to a single thread.

Some of the advantages:

  • no problems with memory consistency or thread interference since the shared data can't be changed
  • no need to use synchronized methods

Possible disadvantages:

  • can't update an immutable object
  • less efficient if you have to often create new copies instead of updating

You should check out the java.util.concurrent package of Java SE. There are plenty of options on keeping things synchronized. If that doesn't work for you, Google Guava has some interesting additions to this package.


Have you had a look at atomic variables?


The author of the article Brian Geotz also wrote a very good book "Java Concurrency in practice"

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