users@jersey.java.net

Re: Updating an Object

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 11 Apr 2008 18:14:52 -0400

On Apr 11, 2008, at 2:44 PM, Prat wrote:
>
> How do I set the field so that the consequent GET operation returns
> the newly set value 'world' instead of the original value 'hello'
> without annotating the resource with @Singleton(it works if it is
> made singleton or if the field 'message' is static)?
>
By default the runtime creates a new instance of the resource class to
handle each request so instance field values aren't preserved between
requests. To get round this you can do either of the things you
mentioned above (@Singleton overrides the lifecycle so only one
resource class instance is created, a static field is shared by all
instances) or store the string value in some kind of shared resource
rather than a per-instance field.

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.