Synchronization
When two or more threads need access to a shared resource, they need some way to ensure that the resource will be used by only one thread at a time. The process by which this is achieved is called synchronization.
Synchronization can be achieved in two ways:
Using Synchronized Methods
synchronized return_type methodname()
{
//method body
}
Using the Synchronized Statement on an Object of a Class
synchronized(object)
{
// statements to be synchronized
}
No comments:
Post a Comment