One question arose in my mind while studying the implementation of the ReentrantLock class. ReentrantLock is serialized, and the documentation says that any deserialized lock always unlocks regardless of the state when it was serialized. This makes sense because locking and unlocking the state is mainly based on threads at runtime (which hold the lock), and while we deserialize these threads, they may not be available.
Question: why should we block so that it is saved, because it does not save its main state (locked / unlocked)? Now I can assume that this may be for the property of justice of the castle. But justice again depends on the underlying OS, so if we save the lock on one platform and deserialize the other, because (write once and run anywhere), it may not work, so do not persist in justice only.
Hopefully I clearly put my confusion on locking serialization in java.
source share