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

Why is string buffer better than string ?

601


List some important characteristics on jre

596


What is java life cycle?

539


explain the concept of virtual method invocation in polymorphism in detail?

1719


Is java ee a framework?

521






Explain about anonymous inner classes ?

580


What is the difference between throw and throws in java?

559


Can main() method in java can return any data?

646


What is the purpose of the file class in java programming?

532


What does this mean java?

561


How do I convert a string to an int in java?

553


What is the purpose of static keyword in java?

519


Why isn’t there operator overloading?

597


How do you compare two objects?

524


How does multithreading take place on a computer with a single cpu in java programming?

536