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 access modifiers can be used for variables?
What is public static?
Why do we need data serialization?
Can you give few examples of final classes defined in java api?
Can a function return a function?
what is thread? : Java thread
Can we serialize arraylist in java?
What is the difference between array list and vector in java?
What is the difference amongst jvm spec, jvm implementation, jvm runtime ?
Can a class have more than one object?
What is anti pattern in java?
What is the difference between serial and throughput garbage collector?
How do you sort a set in java?
Why is a singleton bad?
How can you set an applet’s height and width as a percentage?