Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is the difference between Synchronizing mehtod &
Synchronizing block?

Answers were Sorted based on User's Feedback



What is the difference between Synchronizing mehtod & Synchronizing block?..

Answer / anjani kumar jha

In syncronizing block the object is locked.
In Syncronozing the method the method is
locked........means only one at a time only one thread can
use that method.


Thanks and Regards
Anjani Kumar Jha
9623154095

Is This Answer Correct ?    2 Yes 2 No

What is the difference between Synchronizing mehtod & Synchronizing block?..

Answer / kanu butani

The Java programming language provides two basic
synchronization idioms: synchronized methods and
synchronized statements.

The more complex of the two, synchronized statements, are
described in the next section. This section is about
synchronized methods.

To make a method synchronized, simply add the synchronized
keyword to its declaration:

public class SynchronizedCounter {
private int c = 0;

public synchronized void increment() {
c++;
}

public synchronized void decrement() {
c--;
}

public synchronized int value() {
return c;
}
}

If count is an instance of SynchronizedCounter, then making
these methods synchronized has two effects:
First, it is not possible for two invocations of
synchronized methods on the same object to interleave. When
one thread is executing a synchronized method for an
object, all other threads that invoke synchronized methods
for the same object block (suspend execution) until the
first thread is done with the object.
Second, when a synchronized method exits, it automatically
establishes a happens-before relationship with any
subsequent invocation of a synchronized method for the same
object. This guarantees that changes to the state of the
object are visible to all threads.
Note that constructors cannot be synchronized — using the
synchronized keyword with a constructor is a syntax error.
Synchronizing constructors doesn't make sense, because only
the thread that creates an object should have access to it
while it is being constructed.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More Core Java Interview Questions

What is the difference between integer parseint and integer valueof?

0 Answers  


What are different types of encoding?

0 Answers  


What is the full name of java?

0 Answers  


List the different types of classloaders in java.

0 Answers  


class A{ class B{ } } in which name u save the file,its the program compile?

6 Answers   HCL,


What is string in java is it a data type?

0 Answers  


Can there be an abstract class with no abstract methods in it?

1 Answers  


Can an interface extend a class?

0 Answers  


Can we write multiple catch blocks under single try block?

0 Answers  


What is 'finally' method in Exceptions?

4 Answers  


What is a singleton factory?

0 Answers  


Explain implementation and how is it different from conversion?

0 Answers   Aricent,


Categories