Concurrent Access Problems and Synchronized Threads


  • synchronized methods prevent more than one thread from accessing an object's critical method code simultaneously.
  • You can use the synchronized keyword as a method modifier, or to start a synchronized block of code.
  • To synchronize a block of code (in other words, a scope smaller than the whole method), you must specify an argument that is the object whose lock you want to synchronize on.
  • While only one thread can be accessing synchronized code of a particular instance, multiple threads can still access the same object's unsynchronized code.
  • When a thread goes to sleep, its locks will be unavailable to other threads.
  • static methods can be synchronized, using the lock from the java.lang.Class instance representing that class.