Google App Engine 推送任务 - 使用 DeferredTasks 而不是工作人员服务警告

Google App Engine Push Task - Using the DeferredTasks instead of a worker service warning

关于在 documentation 中使用 DeferredTask 的警告说:

Warning: While the DeferredTask API is a convenient way to handle serialization, you have to carefully control the serialization compatibility of objects passed into payload methods. Careful control is necessary because unprocessed objects remain in the task queue, even after the application code is updated. Tasks based on outdated application code will not deserialize properly when the task is decoded with new revisions of the application.

我不明白这个。 "careful control" 是什么意思?有没有人有一个例子可以说明如何写一个糟糕的DefeferredTask

Java 序列化遵循某些您需要了解的规则。默认情况下,对 Java class "breaks" 序列化的任何更改;用旧 class 序列化的对象不能用新 class.

反序列化

如果您在 class 中声明 serialVersionUID(并且不更改值),则即使您更改 class 也将允许反序列化。如果您习惯于序列化 to/from JSON 和 adding/removing 字段 to/from 您的 classes,它将执行您通常期望的操作。即,从 classes 中删除的字段将忽略数据,添加的新字段将具有默认值。

有些人讨厌 Java 序列化,有些人喜欢它。在使用任务队列时,它很有用,而且非常方便。如果你总是声明一个 serialVersionUID 你可能会没事......当你尝试序列化数据时,大多数错误都会导致异常,你会很快发现这些。