Hello Marc,
>>> The key word is singleton. If a resource class is a singleton then
>>> you only have one instance. For performance that instance needs to
>>> be reentrant. If you just inject an int then all threads servicing
>>> concurrent requests will see the same value. Also injection only
>>> happens at object creation time so only values from the first
>>> request are injected. See the problem ?
>> Yes, I see that, for the case, that the resource classes are singeltons.
>> But the specification says, that "A new resource class instance is
>> created for each request to that resource." (section "Resource
>> Classes", subsection "Lifecycle and Environment"). If a new instance
>> is newly created for every HTTP request, than it's not a singelton.
>> Or do I miss something?
> Good catch. I think that per-request should be the default lifecycle
> but we shouldn't prevent others like singleton being used. E.g. an
> implementation that defers to Spring for resource class instantiation
> should be able to use any of the Spring-defined lifecyles.
ok, that's another question, if this should be so. I think you should
think about if it is useful to allow instance variables and so on on
(sub) resource classes, but forbid it on root resource classes.
Than the sentence "A new resource class instance is created for each
request to that resource." (section "Resource Classes", subsection
"Lifecycle and Environment") should be precised, that this is not valid
for root resource classes. In my understanding every root resource class
is also a root resource class (also if not explicit defined, but the
word construction intends this. Also the last sentence of subsection
"Constructors" of section "Resource Classes" intends this, because it
explicit talks of non-root resource classes.
If a root resource class is not always a resource class, this must
explicit defined at the points in the specification, where there is a
difference.
A better way (IMO) for this is to rename the (non-root) "resource class"
in "sub resource class" (or something like this) and define "resource
class" as both (sub and root resource classes).
regards
Stephan