用jsr305 ThreadSafe注解的接口是什么意思?

What does interface annotated with jsr305 ThreadSafe mean?

@ThreadSafe
public interface ServerInterceptor {
    ...
}

我正在开发 gRPC server

我发现接口ServerInterceptor被注释为@ThreadSafe。当我想实现ServerInterceptor时,我对这个注释感到困惑。

这是否意味着我需要确保 线程安全 执行?

通过使用注释 @ThreadSafe 注释 class/interface,并不意味着 class 是线程安全的。程序员需要使 class 成为线程安全的,而不是使用此注释对 class 进行注释。

在你的例子中,通过注释接口 ServerInterceptor@ThreadSafe 可能意味着,将为该接口编写实现 class 的人必须使 class 作为线程安全的。

所以这只是为了提高可读性,并向同事程序传达一个信息,即这个人在编写这个界面时的想法。

@ThreadSafe 只是向其他程序员using/implementing interface/class 表明它应该是线程安全的。但是不保证任何事情。