Skip to content

Commit e3ae3db

Browse files
committed
[docs update]serialVersionUID 解释完善
1 parent a1a79a3 commit e3ae3db

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

docs/java/basis/serialization.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ public class RpcRequest implements Serializable {
8383

8484
`static` 修饰的变量是静态变量,位于方法区,本身是不会被序列化的。 `static` 变量是属于类的而不是对象。你反序列之后,`static` 变量的值就像是默认赋予给了对象一样,看着就像是 `static` 变量被序列化,实际只是假象罢了。
8585

86+
官方说明如下:
87+
88+
> A serializable class can declare its own serialVersionUID explicitly by declaring a field named `"serialVersionUID"` that must be `static`, `final`, and of type `long`;
89+
>
90+
> 如果想显式指定 `serialVersionUID` ,则需要在类中使用 `static``final` 关键字来修饰一个 `long` 类型的变量,变量名字必须为 `"serialVersionUID"`
91+
92+
也就是说,`serialVersionUID` 只是用来被 JVM 识别,实际并没有被序列化。
93+
8694
**如果有些字段不想进行序列化怎么办?**
8795

8896
对于不想进行序列化的变量,可以使用 `transient` 关键字修饰。

docs/system-design/schedule-task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Kafka、Dubbo、ZooKeeper、Netty 、Caffeine 、Akka 中都有对时间轮的
147147
148148
时间轮简单来说就是一个环形的队列(底层一般基于数组实现),队列中的每一个元素(时间格)都可以存放一个定时任务列表。
149149
150-
时间轮中的每个时间格代表了时间轮的基本时间跨度或者说时间精度,加入时间一秒走一个时间格的话,那么这个时间轮的最高精度就是 1 秒(也就是说 3 s 和 3.9s 会在同一个时间格中)。
150+
时间轮中的每个时间格代表了时间轮的基本时间跨度或者说时间精度,假如时间一秒走一个时间格的话,那么这个时间轮的最高精度就是 1 秒(也就是说 3 s 和 3.9s 会在同一个时间格中)。
151151
152152
下图是一个有 12 个时间格的时间轮,转完一圈需要 12 s。当我们需要新建一个 3s 后执行的定时任务,只需要将定时任务放在下标为 3 的时间格中即可。当我们需要新建一个 9s 后执行的定时任务,只需要将定时任务放在下标为 9 的时间格中即可。
153153

0 commit comments

Comments
 (0)