Understanding the Jersey server-side configuration properties

Each application is different and must be tuned separately. Things that work for one application do not necessarily work for another. Keeping this point in mind, Jersey offers various server-side configuration properties to optimize the runtime performance of RESTful web services. The following table lists some of the core properties that you may find useful while tuning RESTful web APIs.

To view the complete list of configuration properties offered by Jersey, visit the following Appendix page in the Jersey User Guide: 
https://jersey.github.io/documentation/latest/appendix-properties.html

Here are a few major configuration properties with a detailed explanation for each:

Configuration Property

Description

jersey.config.server.subresource.cache.size

This property takes an integer value that defines the cache size for subresource locator models. The default value is 64. Caching of subresource locator models is useful for avoiding the repeated generation of subresource models while processing the request. The runtime identifies the cached subresource with the RESTful web API URI and the input parameter values.

jersey.config.server.subresource.cache.age

This property takes an integer value that defines the maximum age (in seconds) for cached subresource locator models. This is not enabled by default. This is useful for reducing the memory footprint when your application is idle.

jersey.config.server.subresource
.cache.jersey.resource.enabled

This property takes a true or false value. If it is set to true, then Jersey will cache resources in addition to caching subresource locator classes and instances (which are cached by default). To leverage this feature, your resource method needs to return the same resource instances for the same input parameters. This is not enabled by default.

You can configure these properties either by extending the org.glassfish.jersey.server.ResourceConfig class or by using init-param in web.xml as follows:

  • Configuring server-side properties by extending ResourceConfig:
@Provider 
@javax.ws.rs.ApplicationPath("webresources") 
public class ApplicationConfig extends ResourceConfig { 
 
      public ApplicationConfig(@Context ServletContext  
         context) { 
        //Specify server-side configuration properties 
        property(ServerProperties 
            .SUBRESOURCE_LOCATOR_CACHE_SIZE, 1000); 
        property(ServerProperties 
            .SUBRESOURCE_LOCATOR_CACHE_AGE, 60 * 10);       
      } 
} 
  • Specifying configuration properties in web.xml:
<web-app ...> 
    <servlet> 
        <servlet-name> 
           JerseyRestApplicationServlet 
        </servlet-name> 
        <servlet-class> 
           org.glassfish.jersey.servlet.ServletContainer 
        </servlet-class> 
        <init-param> 
            <param-name> 
              jersey.config.server.subresource.cache.size 
            </param-name> 
            <param-value>1000</param-value> 
        </init-param>  
    <init-param> 
            <param-name> 
              jersey.config.server.subresource.cache.age 
            </param-name> 
            <param-value>600</param-value> 
        </init-param>  
    </servlet> 
</web-app> 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.200.3