top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What are synchronized methods and synchronized statements in Java Programming?

0 votes
347 views
What are synchronized methods and synchronized statements in Java Programming?
posted Mar 11, 2016 by Vijay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

In java,If we declare any method as synchronized (keyword) then this method will be known as synchronized method and this method is used to lock an object for any shared resource.When a thread invokes a synchronized method, it automatically acquires the lock for that object and releases it when the thread completes its task.Example:

 public class SynchronizedCounter {
    private int c = 0;
    public synchronized void increment() {
        c++;
    }
    public synchronized int value() {
        return c;
    }
}

and Synchronized Statement executes when the thread has obtained a lock for the object or the class that has been referred to in the statement. Synchronized statement contains a synchronized block, within which is placed objects and methods that are to be synchronized.See this example:

int count=0;
    public void concatenateString(String string)
    {
          synchronized(this) 
          {                                             // Synchronized Statement
          stringOne= string;
          count++;
          }
         stringList.concatenateString(string);
    }
answer Mar 12, 2016 by Shivam Kumar Pandey
Similar Questions
0 votes

I was going through SYNC protocol specification i.e 25.446 and stopped at Timestamp field since there were two terms (synchronization sequence and synchronization period) mentioned and I could not understand.
Can someone please explain these two terms and tell me what is the significance of timestamp at eNodeB when an SYNC PDU receives over M1 interface ?

+1 vote

How an UE makes out it has lost uplink synchronization with serving cell and what steps it take to re-synchronize it ?

...