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 are the library functions in java?
How to perform merge sort in java?
Difference between linkedlist and arraylist.
How java enabled high performance?
What is lambda programming?
What is string literal in java?
What is the difference between equals() and == in java?
How do I get a substring?
What is boolean example?
Can a constructor be protected?
What is the best way to findout the time/memory consuming process?
What are the rules for naming an array?
What are the advantages of exception handling?
we have syntax like for(int var : arrayName) this syntax is to find whether a number is in the array or not.but i want to know how to find that number's location.
Why synchronization is important?