How can we achieve thread safety in Java?
Answers
Answered by
0
There are three ways to construct thread-safe Javaclass which has some state:
Make it truly immutable. public class MyClass { private final int number; public MyClass(int number) { this. ...
Make field number volatile . ...
Use a synchronized block.
Make it truly immutable. public class MyClass { private final int number; public MyClass(int number) { this. ...
Make field number volatile . ...
Use a synchronized block.
Similar questions