dev@jsr311.java.net

Re: JSR311: _at_Target of FIELD for _at_*Param annotations

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 10 Mar 2008 10:04:50 -0400

On Mar 7, 2008, at 4:57 PM, Stephan Koops wrote:

> Hello Marc,
>> public class SomeClass {
>>
>> @PathParam("id") int id;
>>
>> ...
>> }
>>
>> will cause problems if SomeClass is a singleton because you can't
>> (AFAIK) proxy an int.
> why could you not inject the int directly? Why do we need a proxy?
> I changed the annotations @HeaderParam and @PathParam local for me,
> so that they are allowed on fields. It works fine with String and int.
>
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 ?

Injecting a thread-local proxy is one way round this, you still only
have a single instance of the resource class but each service thread
gets its own values of injectables. The proxy hooks back to the
request context to extract a current value rather than the value for
the first request.

Marc.

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