You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 28, 2018. It is now read-only.
JAX-RS Specification 2.1 Chapter 4.1 Line 1: "By default a single instance of each provider class is instantiated for each JAX-RS application."
Jersey clearly violates this rule as it creates one instance of such a class per provider interface this class implements. For example, in case a class is annotated with @Provider and implements both ContainerRequestFilter and ContainerResponseFilter then Jersey creates two instances, instead one instance. In case this class additionally implements Feature then Jersey even creates a third instance.
Can be reproduce using the following code:
@Provider
public class MyProvider implements Feature, ContainerRequestFilter, ContainerResponseFilter {
@Override
public boolean configure(FeatureContext context) {
System.out.println("Feature.this = " + this);
return true;
}
@Override
public void filter(ContainerRequestContext requestContext) {
System.out.println("ContainerRequestFilter.this = " + this);
}
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
System.out.println("ContainerResponseFilter.this = " + this);
}
}
Here is the result it prints after the first invocation finished:
FYI: Using jVisualVM I noticed that the three mentioned instances actually are kept in memory even after a GC got performed. This looks like a memory leak, as at least the Feature instance is of no use at runtime (the other two instances actually get used by every invocation).
JAX-RS Specification 2.1 Chapter 4.1 Line 1: "By default a single instance of each provider class is instantiated for each JAX-RS application."
Jersey clearly violates this rule as it creates one instance of such a class per provider interface this class implements. For example, in case a class is annotated with
@Provider
and implements bothContainerRequestFilter
andContainerResponseFilter
then Jersey creates two instances, instead one instance. In case this class additionally implementsFeature
then Jersey even creates a third instance.Can be reproduce using the following code:
Here is the result it prints after the first invocation finished:
To be compliant to the mentioned chapter of the spec, the result MUST be this instead:
The text was updated successfully, but these errors were encountered: