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

Answer Posted / vikki

There are two ways to syanchronize access to an object

1st one is using synchronized keyword for example

Synchronized type methodname(arg-list)
{
//synchrinized method body
}

2nd way s using synchronized block

synchronized(object)
{
//synchronized statement

}

Is This Answer Correct ?    30 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of java inner classes?

563


How many types of design patterns are there?

534


What do you mean by local variable and instance variable?

519


Is class is a data type?

574


Mention a package that is used for linked list class in java.

529






What is the difference between compile-time polymorphism and runtime polymorphism?

570


what is the purpose of using rmisecuritymanager in rmi?

570


Explain the polymorphism principle?

587


What is protected access modifier?

584


What is downcasting?

576


Is main a keyword in java?

542


5 Coding best practices you learned in java?

640


what do you mean by classloader?

555


Why should we use singleton pattern instead of static class?

466


What are reference variables in java?

600