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.

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

Unknown 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


Unknown 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


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


Unknown 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


gowsalya 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


Mounika 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


Unknown 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


gowthunan said...
17 November 2018 at 12:16

Greetings from Florida! I’m bored at work, so I decided to browse your site on my iPhone during lunch break
fire and safety course in chennai


pooja said...
13 December 2018 at 10:13

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
Java training in Bangalore | Java training in Jaya nagar

Java training in Bangalore | Java training in Electronic city

Java training in Chennai | Java training institute in Chennai | Java course in Chennai

Java training in USA


jeyanthi said...
19 December 2018 at 20:13

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
Data Science training in Chennai | Data Science Training Institute in Chennai | Data Science Course in Chennai
Data science training in Bangalore | Data Science Training institute in Bangalore
Data science training in pune | Data Science training institute in Pune
Data science online training | online Data Science certification Training-Gangboard
Data Science Interview questions and answers
Data Science Tutorial


VRITPROFESSIONALS said...
21 January 2019 at 15:48

Nice post. Thanks for sharing! I want people to know just how good this information is in your blog. It’s interesting content and Great work.

Thanks & Regards,
VRIT Professionals,
No.1 Leading Web Designing Training Institute In Chennai.

And also those who are looking for
Web Designing courses training institutes in Chennai
HTML courses training institutes in Chennai
CSS courses training institutes in Chennai
Bootstrap courses training institutes in Chennai
Photoshop courses training institutes in Chennai
PHP & Mysql courses training institutes in Chennai


ganapathi said...
30 January 2019 at 12:33

Thank you for excellent article.

Please refer below if you are looking for best project center in coimbatore

final year projects in coimbatore
Spoken English Training in coimbatore
final year projects for CSE in coimbatore
final year projects for IT in coimbatore
final year projects for ECE in coimbatore
final year projects for EEE in coimbatore
final year projects for Mechanical in coimbatore
final year projects for Instrumentation in coimbatore


Jaweed Khan said...
20 February 2019 at 17:41

Thanks For Sharing The Information The Information shared Is Very Valuable Please Keep Updating Us Time Just Went On reading The Article Python Online Training Aws Online Course DataScience Online Course Devops Online Course


Nisha San said...
6 July 2019 at 17:28

Hey, would you mind if I share your blog with my twitter group? There’s a lot of folks that I think would enjoy your content. Please let me know. Thank you.
Java Training in Chennai | J2EE Training in Chennai | Advanced Java Training in Chennai | Core Java Training in Chennai | Java Training institute in Chennai


Alwin Co Daan said...
12 October 2019 at 12:48

Final Year Projects for CSE

Corporate TRaining Spring Framework

Project Centers in Chennai For CSE

Spring Training in Chennai


unknown said...
24 October 2019 at 17:58

Hiii...Thanks for sharing great info...Nice post...Keep move on...
Blockchain Training in Hyderabad


Data Science Course said...
20 July 2020 at 23:06

I feel really happy to have seen your web page and look forward to so many more entertaining times reading here. Thanks once more for all the details.
Data Science Training in Hyderabad


Best Data Science Courses In Bangalore said...
25 July 2020 at 20:43

Great post! I am actually getting ready to across this information, is very helpful my friend. Also great blog here with all of the valuable information you have. Keep up the good work you are doing here.
Best Data Science Courses in Bangalore


Jackie Co Kad said...
11 August 2020 at 11:21

Great Article
Artificial Intelligence Projects

Project Center in Chennai



JavaScript Training in Chennai

JavaScript Training in Chennai


saketh321 said...
8 January 2021 at 15:28


This is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works ExcelR Data Analytics Course


Thermal Boiler Process said...
27 January 2021 at 10:10

Amazing blog post , thanks for sharing with us

Best Digital Marketing Training in Bangalore


Business Analytics Course said...
13 June 2021 at 00:39

Just a shine from you here. I have never expected anything less from you and you have not disappointed me at all. I guess you will continue the quality work.
Business Analytics Course


Data Analytics Course in Bangalore said...
13 June 2021 at 18:51

I like to see websites that include the price of free shipping from the excellent helpful resource. I really enjoyed reading your post. Thank you!Data Analytics Course in Bangalore


Digital Marketing Course in Bangalore said...
15 June 2021 at 08:55

Now is the perfect time to plan for the future and now is the time to be happy. I have read this article and if I can I would like to suggest some cool tips or advice. Perhaps you could write future articles that reference this article. I want to know more!
Digital Marketing Course in Bangalore


Digital Marketing Course said...
9 September 2021 at 14:02

It's like you've got the point right, but forgot to include your readers. Maybe you should think about it from different angles.
Digital Marketing Course in Bangalore


Career Programs Excellence said...
8 December 2021 at 19:03

Very good message. I came across your blog and wanted to tell you that I really enjoyed reading your articles.


IoT Training in Bangalore


Professional Academic Institute said...
3 June 2022 at 00:54

Companies are increasingly turning to data for decision-making and are depending on data professionals to do so. Develop strong logical and numerical aptitude and learn to work with R, Python, SQL, Hadoop, and statistical techniques like Linear Regression, Logistic Regression, etc. Sign up for the Data Scientist training in Bangalore, and gain expertise in using sophisticated analytical methods and statistical methods to prepare data for predictive and prescriptive modeling.

Data Science Course in Bangalore


Educational Courses said...
6 June 2022 at 23:45

Fast forward your career with the best Data Analyst Course offered by 360DigiTMG. Get trained by expert trainers with placement assistance.


Data Science Course in Delhi


Restly said...
14 November 2024 at 16:57

Amazing content as always! I appreciate the time and research you put into these posts. Luxury Italian Furniture Stores in Hyderabad


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar