How to make a method thread safe without using synchronized
keyword?

Answer Posted / jitender arora

By using a flag to determine that the method is in use by a
running thread.

Class A{

private boolean inUse = false;

public methodA(){
if(!inUse){
inUse = true;
...
...
...
inUse = false;
}
}

}

Is This Answer Correct ?    18 Yes 12 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a values collection view ?

885


What is thread pool? How can we create thread pool in java?

847


What is space character in java?

808


Why lambda expression is used in java?

786


What is a consumer in java?

793


Differentiate between class and structure.

830


Explain the difference between an object-oriented programming language and object-based programming language?

777


What are the differences between processes and threads?

775


What is an arraylist in java?

734


Which package has light weight components in java programming?

899


Which class is the superclass of all classes?

853


How many bytes is a url?

773


Explain thread in java?

889


Can we override a variable in java?

774


What is java util?

802