What does interface annotated with jsr305 ThreadSafe mean?

739 Views Asked by At
@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?

2

There are 2 best solutions below

1
Deepak Kumar On BEST ANSWER

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.

0
Pete On

@ThreadSafe is just an indication to other programmers using/implementing the interface/class that it SHOULD be thread safe. Doesn't guarantee anything however.