Java- synchronized modifier / Chapter -7/ Access Modifier


java synchronized modifier

 Java synchronized  modifier


1." synchronized" is a modifier applicable for methods and blocks but not for classes and variables.

2.If multiple threads are trying to operate simultaneously on the same java object then, there may be a chance of data inconsistency problem.This is called "Race Condition".We can overcome this problem by using synchronized keyword or modifier.




3.If a method or block declared as synchronized then at a time only one thread is allowed to execute that method or block on the given objects so that data inconsistency problem won't come.

4.But the main disadvantage of "synchronized" modifier is, it increasing waiting time of the threads & creates performance problems.hence if there is no specific requirement then it is not recommended to use synchronized keyword.

5.synchronized method compulsory contains implementation whereas abstract method doesn't contain any implementation hence "abstract synchronized" is an illegal combination of methods.

No comments:

Post a Comment

Be the first to comment!

Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.

Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.

Regards,
JavaByChetan
Back To Home

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com