Lifecycle options

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 09 Jul 2007 15:29:45 -0400

We decided that the default lifecycle for a resource class would be
per-request but didn't rule out others. Another obvious candidate is
a per-application singleton and, while its possible for resource
class methods to defer to an application-managed singleton, I think
it would be worth going the extra-mile to offer that option in the
API. I propose to add a @Scope annotation as follows:

public @interface Scope {
     public enum Lifecycle {REQUEST, APPLICATION};

     public Lifecycle value() default Lifecycle.REQUEST;

Omission of the annotation would be equivalent to inclusion with a
value of REQUEST.

A root resource class annotated with @Scope(APPLICATION) would be
required to a have a zero argument constructor and be thread-safe.
The JSR 311 implementation would only ever instantiate a single
instance per application and re-use that for all requests.

Thoughts ?

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