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 a values collection view ?
What is thread pool? How can we create thread pool in java?
What is space character in java?
Why lambda expression is used in java?
What is a consumer in java?
Differentiate between class and structure.
Explain the difference between an object-oriented programming language and object-based programming language?
What are the differences between processes and threads?
What is an arraylist in java?
Which package has light weight components in java programming?
Which class is the superclass of all classes?
How many bytes is a url?
Explain thread in java?
Can we override a variable in java?
What is java util?