educative.io

How to make thread safe?

I don’t understand this part .

“Note that composition of two or more thread-safe classes doesn’t guarantee the resulting type to be thread-safe.”

Then what’s the right way to make thread safe?

Hi @Franklin
There are no silver bullets for making class Thread safe, all you need to do is to ensure that the methods of your class don’t cause deadlocks and for that, there are so many useful classes in Java, like AtomicInteger, Locks, Semaphores, etc.

I hope this is helpful.