users@jersey.java.net

Re: [Jersey] Initialization at startup, as opposed to first request?

From: Pavel Bucek <Pavel.Bucek_at_Sun.COM>
Date: Thu, 10 Jun 2010 20:07:52 +0200

Hello Jeff,

you can control this in web.xml, concretely add load-on-startup into
servlet element.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.sun.jersey.samples.helloworld.resources</param-value>
</init-param>
*<load-on-startup>1</load-on-startup>*
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Regards,
Pavel


On 6/10/10 7:44 PM, Jeff Crump wrote:
> I've noticed that the first request I send to my Jersey application
> takes a bit longer than subsequent ones -- I presume this is Jersey
> looking at my classes and assembling the infrastructure.
>
> Is there a way to force this initialization, say, when my servlet
> starts up - as opposed to on the first request?
>
> Thanks,
>
> Jeff
>