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
What is the difference between the paint() and repaint() methods?
Are strings immutable in java?
What is singleton pattern?
What is the abstract class?
What will be the default values of all the elements of an array defined as an instance variable?
What exactly is a .class file?
Explain thread in java?
What is jit and its use?
What are the 3 types of control structures?
What happens if a constructor is declared private?
What are drawbacks of singleton class?
How do you add an arraylist to an array in java?
How do you write a good declaration?
Are global variables initialized to zero?
What do bitwise operators do?