我应该将 GryoMapper 声明为静态字段吗?
Should I declare GryoMapper as a static field?
看了下面的代码,好像是线程安全的。
希望能像这样使用
class Foo {
private static final GryoMapper MAPPER = GryoMapper.build().create();
}
而不是
class Foo {
private final GryoMapper MAPPER = GryoMapper.build().create();
}
Gryo 基于 not thread-safe 的 Kryo。 GryoMapper
基本上只是 Kryo
实例的构建器,这意味着您应该能够在没有 static
声明的情况下将其初始化为成员变量。请确保您从 GryoMapper
生成的 Kryo
实例不会被多个线程同时访问,如 Kryo link 中所述。
看了下面的代码,好像是线程安全的。
希望能像这样使用
class Foo {
private static final GryoMapper MAPPER = GryoMapper.build().create();
}
而不是
class Foo {
private final GryoMapper MAPPER = GryoMapper.build().create();
}
Gryo 基于 not thread-safe 的 Kryo。 GryoMapper
基本上只是 Kryo
实例的构建器,这意味着您应该能够在没有 static
声明的情况下将其初始化为成员变量。请确保您从 GryoMapper
生成的 Kryo
实例不会被多个线程同时访问,如 Kryo link 中所述。