Thread Synchronization - Online Code


If a method declared as the synchronized at a time only one thread is allowed to execute that synchronized method on any given object or class. Every Object in java has a lock. At the time of synchronization only the lock concept will come into the picture. this lock also known as a monitor When a thread needs to enter a static synchronized method, it acquires the monitor of the Class object associated with the particular class to which the static method belongs to whereas in case of a synchronized instance method, the thread requires to obtain the monitor of the particular object on which the method call is being made.

Source Code

class Display
static int x=10;
int y=56;
public synchronized static void show(String name,int a)
System.out.println("start the method show"+"  "+x);
... (login or register to view full code)

To view full code, you must Login or Register, its FREE.

Hey, registering yourself just takes less than a minute and opens up a whole new GetGyan experience.


No comment yet. Be the first to post a comment.