How the threads are synchronized?

Answer Posted / seshadri pera

Threads are synchronized in two ways.

1) block level
2) Method level

Block level synhronization is the better performance
compare to method level.

Block Level:
see the code syntax for block level
synchronized {..
....//code to lock the specific object here..
...}

Method Level:
See the syntax
public void synchronized XXXMethodName(Parameters or
object to acquire locking){.....
...}

Is This Answer Correct ?    7 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the significance of class loaders in bootstrap?

502


What is anagram number?

458


Explain the significance of listiterator.

592


Is minecraft 1.15 out?

551


What is replacefirst in java?

578






How to pass arraylist to stored procedure in java?

550


What is the use of set in java?

614


What is class variable java?

587


Difference between string s= new string (); and string s = "abv";?

744


What are streams?

638


What is a stack class in java ?

614


What is return data type?

563


Suppose if we have variable ' I ' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared?

547


Is final static java?

553


What is executor memory?

527