Post a Job  |   Ask a Question?   |   Already registered? login or register
srikanth reddy
22/05/2015 03:02 AM

what is the diff b/w normal synchronization and static synchronization?


can any one respond ...
Spam    4 Comments

Ramakanth,reddy
22/05/2015 05:03:27
normal synchronization menas on java objects [OBJECT LEVEL] ex: we will perform like this Employee e=new Employee(); synchronize(e){ } normal synchronization menas on class [CLASS LEVEL] ex: we will perform like this Employee e=new Employee(); synchronize(Employee.class){ }

srikanth,reddy
22/05/2015 12:58:31
please give more information..

Ramakanth,reddy
22/05/2015 21:14:46
In java every object contains one lock and every class contains one lock. object level lock ========== if a thread wants to execute synchronized method [or] block on the given object ,first it has to get lock of that object .once thread got lock ,then it is allowed to execute any synchronized method on the given object.once synchronization method execution completes automatically thread releases the lock. while thread executing synchronized method on the given object,remaining threads are not allowed to execute any synchronized method.But remaing threads are allowed to execute non-synchronized methods on that same object Note:If multiple threads are operating on multiple objects then synchronization is not required.If multiple threads are operating on same object then synchronization is required. ex: we will perform like this class Employee { public synchronized void m1(){} public void m2(){} } Employee e=new Employee(); synchronize(e){ } here synchronized m1() is executed by one thread at a time.but non-synchronized m2() is executed by multipe threads at a time. class level lock ========== every class has a unique lock (classlevel lock) if thread wants to execute a static synchronization method then it has to get class level lock ,then it is allowed to execute any static synchronized method of that class. remaining lock concept same as object level lock class A { static synchronized m1(){} static synchronized {} static m3(){} } if we perform class level lock on class A as following below synchronized (A.class) { } then synchronized static block and synchronized static m1() are executed by one thread at a time .But non-synchronized static m3() is executed by multiple threads at a time. I HOPE IT IS CLEAR

srikanth,reddy
23/05/2015 00:38:02
thanks boss..

Languages :
xml