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 the difference between the paint() and repaint() methods?

798


Are strings immutable in java?

733


What is singleton pattern?

778


What is the abstract class?

768


What will be the default values of all the elements of an array defined as an instance variable?

772


What exactly is a .class file?

811


Explain thread in java?

871


What is jit and its use?

767


What are the 3 types of control structures?

718


What happens if a constructor is declared private?

790


What are drawbacks of singleton class?

714


How do you add an arraylist to an array in java?

724


How do you write a good declaration?

696


Are global variables initialized to zero?

709


What do bitwise operators do?

738