What is the difference between thread safe and thread compatible?

thread safe means that the object is safe to use concurrently in multiple threads, it is implemented by java self; although thread compatiple is not thread safe, it still can be safe to use concurrently when you surround some synchronization code in your non-thread-safe code or have a wrapper object where it is thread safe.Namely that you shoud implement is by yourself.


Thread safe means that an object can be used by many threads concurrently and still be correct 1

Thread hostile means that the object does something (mutates static state, thread local storage etc.) that prevents it from being thread safe.

Thread compatible means not thread safe, but not thread hostile - so to satisfy thread safety, the user must perform synchronization themselves


1 But the definition of correctness varies a little...

Java In Theory And In Practice defines this according to the class's specification.

Geoff Romer at Google and Wikipedia define this as simply lack of data races.

I usually hope this to mean no crashes, deadlocks or other surprises.