Science, asked by chandan8804, 1 year ago

How can we achieve thread safety in Java?

Answers

Answered by RockyAk47
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.

Similar questions