What are the two ways you can synchronize a block of code?

Answer Posted / ajay tiwary

The way you can synchronize the block is:-

synchronized(dummy object)
{
//synchronized statement

}
In dummy object you can use this or u can create a dummy
object by using new Keyword.

What answer Vikki is posted as the first one is not the way
of synchronizing the block but it's a way to synchronizing
a method.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is static block?

593


What is var keyword ?

742


Explain about oops concepts.

636


How does compareto work in java?

580


Can we have try without catch block?

645






When does a class need a virtual destructor?

532


Difference between abstract and concrete class ?

583


What is java util function?

516


What is java dot?

498


What is linkedlist in java?

510


What is the use of isempty in java?

539


What is the difference between stream and buffer?

517


Why is boolean important?

593


What happens if an exception is not handled in a program?

626


What is advantage of java?

544