开发者

Is java.util.Vector serialization thread-safe?

开发者 https://www.devze.com 2023-01-20 01:49 出处:网络
开发者_如何学GoI know the Vector class is thread-safe for adding and removing elements [reference].
开发者_如何学Go

I know the Vector class is thread-safe for adding and removing elements [reference].

If I serialize a Vector using an ObjectOutputStream am I guaranteed a consistent (and non-corrupt) state when I deserialize it even if other threads are adding and removing objects during the seralization?


The writeObject() method is synchronized. But there's nothing in the Javadoc that guarantees that unless it's implied by the statement 'Vector is synchronized'.

Note that the readObject() method doesn't need to be synchronized, as the object isn't accessible to anybody until readObject() returns.

0

精彩评论

暂无评论...
验证码 换一张
取 消