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 private & public & friendly classes?
What is meant by object oriented programming – oop?
What is difference between arraylist and list in java?
How we can declare a static variable?
What is the effect of keeping a constructor private?
What is hashing principle in java?
How do you add an arraylist to an array in java?
How to restrict a member of a class from inheriting by its sub classes?
What is the difference between class forname and new?
What is ph and buffers?
Which number is denoted by leading zero in java?
How many threads can java run?
What does indexof mean?
Explain about the interpreter in java?
What is volatile keyword in java