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


Please Help Members By Posting Answers For Below Questions

What is the static method?

563


What about abstract classes in java?

603


How many bits is a string in java?

567


What do you mean by multithreaded program?

546


What differences exist between iterator and listiterator?

561






What is class variable java?

578


Explain the difference between private, public, package and protected in java?

589


Why wait and notify methods are declared in object class?

596


What is super?

578


What are the differences between string, stringbuffer and stringbuilder?

513


What is the purpose of garbage collection in java?

649


what is server side caching?

1598


How can you read an integer value from the keyword when the application is runtime in java? example?

616


What are the limitations of procedural programming approach?

521


What is the difference between menuitem and checkboxmenu item?

769