views:

49

answers:

2

I have a class that contains an object of type Object (which is used as a monitor for synchronization). Since Objects are not Serializable, what can I substitute to make serialization work?

+9  A: 

I wouldn't think a field used for synchronization would need to be serialized.

Mark it transient.

Jonathon
+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
A: 

A monitor for synchronization? Have you tried with ReentrantLock Like Jonathon said. You should mark it as transient

santiagobasulto