Saturday, October 1, 2011

What do you understand by Synchronization?

Synchronization :

   Two or more threads trying to access the same method at the same point of time leads to synchronization. If that method is declared as Synchronized, only one thread can access it at a time. Another thread can access that method only if the first thread's task is completed.

Example:

Synchronizing a function:

public synchronized void Method () {
// Appropriate method-related code.
}
Example:

Synchronizing a block of code inside a function:

public myFunction (){
synchronized (this) {
// Synchronized code here.
}
}

More about Synchronization click here

No comments:

Post a Comment