Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Explanation on Synchronized keyword  RSS feed

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need explanation for the following passage:
A synchronized method can be accessed by only one thread at a time. Transient variables cannot be serialized. An abstract method does not have an implementation; it has to be implemented by the first concrete subclass of the containing class. The class containing at least one abstract method has to be declared as abstract. However, an abstract class need not have any abstract methods in it:
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That paragraph has at least 3 unrelated topics. Which topic do you not understand?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each object has a "lock" that must be acquired before any of that object's synchronized code can be executed. Threads attempting to execute synchronized code enter a "seeking lock" state, and proceed to the ready state only when the lock is available. There is also a class lock (as opposed to object), which applies to static synchronized code. Unsynchronized methods can be called without acquiring the lock.

When synchronizing methods, the keyword "synchronized" comes first, before the return type. Note that the synchronized modifier is not passed via inheritance -- i.e., methods that are synchronized in a parent class are not synchronized by default in any subclasses.

Non-method blocks can be synchronized on a particular object via synchronized(object){}, whereby the specified object's lock must be acquired before the block can execute.

See the "Concurrency" chapter in Bruce Eckel's Thinking in Java...

http://www.faqs.org/docs/think_java/TIJ315.htm

(I addressed the "synchronized" part of the question because it's in the topic title. But, as Mike pointed out, "transient" and "abstract" are not related to this.)
[ December 29, 2004: Message edited by: marc weber ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!