users@jersey.java.net

Re: [Jersey] Root Resource instantiation

From: Craig McClanahan <Craig.McClanahan_at_Sun.COM>
Date: Fri, 14 Aug 2009 09:53:10 -0700

dloy wrote:
> Again, sorry for a newbie question, is a new Root Resource object
> instantiated on each http call (tomcat)? Is it safe to store data to
> local variables in the object or are there thread safe considerations?
Yes, a new root resource instance is created for each request. It's
quite common to store per-request data into instance variables, or let
Jersey inject some things for you:

    @Path("/foo")
    public class FooResource {

        @Context
        private UriInfo uriInfo; // Will be injected by Jersey for you

        ...

    }

> Thanks
> David
>
Craig