SimpleDateFormat is not threadsafe. Read the Javadoc. For StringParamUnmarshaller, Resteasy stores them in a map keyed by classname of the generic type:
For example: class FooUnmarshaller implements StringParamUnmarshaller<Foo> {} FooUnmarshaller will be used to unmarshall Foo classes only. No subclasses of Foo though! That's just the limitation. An unmarshaller instance is created *per method parameter*. setAnnotations is called with the annotations of that parameter. So, if you had this: @GET public STring get(@Bar @HeaderParam("header") Foo arg1, @Stuff @HeaderParam("header") Foo arg2) {} An instance of FooUnmarshaller would be instantiated for arg1. ANother instance created for arg2. On 4/28/2014 1:45 PM, Allen Gilbert wrote: > Hello, > > Per > http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html/StringConverter.html#StringParamUnmarshaller, > I created a @DateFormat annotation for unmarshalling query parameters > into Date objects. Initially, I thought it was working well, but once I > started using more than one date format, I ran into trouble. > > The user guide states that a StringParameterUnmarshaller "is created per > injector," but its JavaDoc says, "Instances of this class are created > per parameter injection." I'm not sure what "created per injector" > means, but I read "created per parameter injection" to mean that my > custom unmarshaller should be instantiated per resource method call. > This is consistent with the example in the user guide, which assumes > that setAnnotations() is called for each request. Otherwise, only one > date format could ever be registered, and also, DateFormatter would not > be thread-safe. > > These are exactly the two issues I've run into: only one date format is > ever used to unmarshal query parameters, so many of my resource methods > fail because of wacky dates. Furthermore, when running at high load, > date parsing sometimes fails when multiple threads access the same > SimpleDateFormat instance. I've verified that the only > time setAnnotations() is called on my custom parameter unmarshaller is > during the very first request, as part of ResteasyDeployment.start(). > > Is this "caching" of StringParameterUnmarshallers by design? > > -Allen > > > ------------------------------------------------------------------------------ > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE > Instantly run your Selenium tests across 300+ browser/OS combos. Get > unparalleled scalability from the best Selenium testing platform available. > Simple to use. Nothing to install. Get started now for free." > http://p.sf.net/sfu/SauceLabs > > > > _______________________________________________ > Resteasy-users mailing list > Resteasy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/resteasy-users > -- Bill Burke JBoss, a division of Red Hat http://bill.burkecentral.com ------------------------------------------------------------------------------ "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE Instantly run your Selenium tests across 300+ browser/OS combos. Get unparalleled scalability from the best Selenium testing platform available. Simple to use. Nothing to install. Get started now for free." http://p.sf.net/sfu/SauceLabs _______________________________________________ Resteasy-users mailing list Resteasy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/resteasy-users