Back to Top

Sunday, 15 January 2012

JAVA : Describe synchronization in respect to multithreading.

With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. synchronization, it is possible for one thread to modify a shared variable while another thread is in the process of using or updating same shared variable. This usually leads to significant errors. So, its the mechanism that ensures that only one thread is accessed the resources at a time.


How to achieve synchronization in java?

In java, synchronization can be achieved by using the 
synchronized keyword. 
It can be used in 2 ways.
1. on a method signature: We can declare synchronized keyword in method signature, therefore, that method will be thread safe in multi-threaded environment. That means, only, one thread at a time can access this method.
Below, method execute() is synchronized, so it is can be accessed by one thread at a time.
       
synchronized void execute(){
  // do something
}
       
2. Write synchronized block: Secondly, we can write a synchronized block, and that block will be synchronized.

synchronized(this){
  // do something
}


The above code, will lock the object itself, when this piece of code has been executed by a thread.

16 Responses to “ JAVA : Describe synchronization in respect to multithreading. ”

Naviya Nair said...
24 October 2016 at 15:01

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai


Naviya Nair said...
24 October 2016 at 15:28

I have read your blog its very attractive and impressive. I like it your blog.

Java Training in Chennai Java Training in Chennai | Core Java Training in Chennai

Online Java Training Java 8 Online Training | Java J2EE Online Training | JavaEE Training Institute in Chennai Java Training Institutes

Java Training Institutes in Chennai Java Training in Chennai


jazz said...
21 March 2017 at 16:26

Superb. I really enjoyed very much with this article here. Really it is an amazing article I had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your..
Vmware Training in Chennai


venkatesh raghunath said...
2 July 2017 at 11:53

Very impressive blog, it is very easy to understand, i really enjoyed to read this. thanks for sharing, keep rocks.
Java Training in chennai | Java Training institute in velachery


Jordan Alexo said...
24 January 2018 at 13:58

Hi admin..,
I am the big follower of your blog. I read all your blog for gathering lot of informations. keep sharing more blogs..,
Regards,
Java training in Chennai|| J2ee training in Chennai


merlinmadonna said...
14 March 2018 at 14:22

Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating.
oracle training in chennai|| hadoop training in chennai


Jordan Alexo said...
4 April 2018 at 14:28

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
Regards,
hadoop training in chennai || selenium training in chennai





Dipanwita said...
10 August 2018 at 13:28

This is a most useful blog post. Will recommend it to all Java enthusiasts. java training in chennai


sudha P said...
25 October 2018 at 15:35

We are a group of volunteers and starting a new initiative in a community. Your blog provided us valuable information to work on.You have done a marvellous job!
Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout

Java training in Bangalore | Java training in Marathahalli | Java training in Bangalore | Java training in Btm layout


johnsy sai said...
26 October 2018 at 16:37

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
Online DevOps Certification Course - Gangboard


amala jst said...
26 October 2018 at 19:06

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 

rpa online training |
rpa course in bangalore |
rpa training in bangalore |
rpa training institute in bangalore


Mouni yoga said...
27 October 2018 at 10:44

This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
python training in rajajinagar | Python training in bangalore | Python training in usa


Naga Manickam said...
29 October 2018 at 18:04

I love the blog. Great post. It is very true, people must learn how to learn before they can learn. lol i know it sounds funny but its very true. . .

Data Science course in Chennai | Best Data Science course in Chennai | Data science course in bangalore | Best Data Science course in Bangalore

Data science course in pune | Data Science Course institute in Pune | Data science online course | Online Data Science certification course-Gangboard

Data Science Interview questions and answers


Vignesh G said...
30 October 2018 at 15:37

I am really happy with your blog because your article is very unique and powerful for new reader.
Click here:
selenium training in chennai
selenium training in bangalore
selenium training in Pune
selenium training in pune
Selenium Online Training


Dwarakesh babu said...
2 November 2018 at 12:24

I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused. Any suggestions? Thanks a lot.



AWS Training in NewYork City | Amazon Web Services Training in Newyork City


AWS Training in London | Amazon Web Services Training in London, UK

Amazon Web Services Online Training in USA | AWS Online Course in USA


sathya shri said...
9 November 2018 at 14:25

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in chennai

automation anywhere online Training

angularjs interview questions and answers


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar
blog links Web Directory Academics Blogs