C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers


10,705 users

Thread Synchronization in java?

0 votes
asked May 14, 2014 by augustaina Sr Member (4,820 points)

1 Answer

0 votes

 When multiple threads wants to access the object at the same time avoiding multiple threads to access the same and giving access to one of the thread is called as thread synchronization. Thread synchronization can be done into two ways.

1.     Synchronized Block

2.     synchronized  Method

1.Synchronized Block: Synchronizing a group of statements or part of a code is called as Synchronized Block.

Syntax: Synchronized(object){

                     Statements;    }

2.Synchronized Method: when we want to Synchronized all the statements in a method we go for synchronized method.

Syntax: Synchronized returnType methodName(){



Note: In the previous program multiple threads acting on the same object leading to data in consistency, to avoid the data inconsistency problem. We have to synchronize the threads acting on the same object.

Ex: public Synchronized void run(){

            Same code previous programs;


When multiple threads are acting on synchronized objects then there is chance of other problems like ‘Deadlock’ occurring in the application.

answered May 14, 2014 by rock Expert (14,990 points)

Related questions

0 votes
1 answer 105 views
0 votes
1 answer 26 views
26 views asked Feb 7, 2014 by john Guru (27,140 points)
+1 vote
2 answers 33 views
33 views asked Jan 30, 2014 by keem Expert (13,240 points)
0 votes
2 answers 31 views
31 views asked Jan 10, 2014 by sara Guru (24,570 points)
0 votes
0 answers 87 views
87 views asked Dec 30, 2013 by Adam Jr Member (380 points)