Search code examples
javajsr305

What does interface annotated with jsr305 ThreadSafe mean?


@ThreadSafe
public interface ServerInterceptor {
    ...
}

I am developing a gRPC server.

I found that the interface ServerInterceptor is annotated with @ThreadSafe. I am confused about this annotation when I want to implement ServerInterceptor.

Does it mean I need to ensure thread safety of implementation?


Solution

  • By annotating a class/interface with annotation @ThreadSafe, it doesn't mean that the class is thread safe. Programmer need to make the class as thread safe and than annotate the class with this annotation.

    In your case by annotation the interface ServerInterceptor with @ThreadSafe probably mean that, the person who will be writing the implementation class for this interface have to make that class as thread safe.

    So this just for readability and to convey a message to colleague program that what the person had in mind while writing this interface.