I have a class that contains an object of type Object
(which is used as a monitor for synchronization). Since Object
s are not Serializable
, what can I substitute to make serialization work?
views:
49answers:
2
+9
A:
I wouldn't think a field used for synchronization would need to be serialized.
Mark it transient
.
Jonathon
2010-07-01 16:59:12
+1, this is the only correct answer. To Jake - an `Object` instance has no internal state; if you stop and think about it, what would you *want* to serialize about it? The answer is inevitably "nothing", hence it should be excluded from the serialization process.
Andrzej Doyle
2010-07-01 17:04:12
A:
A monitor for synchronization? Have you tried with ReentrantLock
Like Jonathon said. You should mark it as transient
santiagobasulto
2010-07-01 17:05:55