serialization - Why Locks are Serializable in java? -


one question arised in mind while looking implementation of reentrantlock class. reentrantlock serializable , in documentation says deserialized lock unlocked irrespective of state when serialized. make sense because state lock , unlock based on threads @ runtime (who hold lock) , while de-serialize threads may not available.

question : why need lock persist because not store it’s basic state (locked/unlocked) ? right can assume may fairness property of lock. fairness again depending on underlying os if persists lock on 1 platform , deserialized on because (write once , run anywhere) may not work no point in persisting fairness.

hope put confusion lock serialization in java.

http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/locks/condition.html http://download.java.net/jdk7/archive/b123/docs/api/java/util/concurrent/locks/reentrantlock.html

i reason why lock persists you're able serialize objects depend on lock itself. if lock wasn't serializable, dependent on wouldn't able serialized either.

you'd able store owner, holdcount, queuedthreads , of other stuff can see on api page linked above reentrantlock.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -