Reputation: 318
I am confused if the below code will wait or skip execution of the block,
synchronized(lock)
{
//Do something...
//...
//...
//...
}
And is it possible to use boolean values as parameter for synchronized? And what are mutex locks? If it is not going to wait, is its only purpose is to make a code statement thread safe and only for critical section based access?
Upvotes: 1
Views: 438
Reputation: 7287
@synchronized will wait until the lock is available. It declares a critical section around the code block. In multithreaded code, @synchronized guarantees that only one thread can be executing that code in the block at any given time.
Upvotes: 3