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 static method?
What about abstract classes in java?
How many bits is a string in java?
What do you mean by multithreaded program?
What differences exist between iterator and listiterator?
What is class variable java?
Explain the difference between private, public, package and protected in java?
Why wait and notify methods are declared in object class?
What is super?
What are the differences between string, stringbuffer and stringbuilder?
What is the purpose of garbage collection in java?
what is server side caching?
How can you read an integer value from the keyword when the application is runtime in java? example?
What are the limitations of procedural programming approach?
What is the difference between menuitem and checkboxmenu item?