Hi, mailing list,
there is problem with org.geoserver.rest.BeanResourceFinder.
Restlet resources are not designed to be thread-safe (response, request are stored in fields… ), but BeanResourceFinder method findTarget:
public Resource findTarget(Request request, Response response){
Resource res = (Resource) applicationContext.getBean(getBeanToFind());
res.init(getContext(), request, response);
return res;
}
returns the same Resource instance to concurrent threads, well, Spring returns the same instance,
workaround is to tell Spring to give different instances, that can be done with scope=“prototype” like:
But it would be nice if it could be fixed in code not in the Spring configuration file, because users may forget to add scope attribute, which may lead to real time errors.
Thank you,
Mārtiņš Linde
Hi Mārtiņš,
You are correct, this is definitely a thread safety issue. I agree that it would be nicer to be able to ensure to clone the object in code rather than rely on the user to set the prototype flag. However that is easier said than done. Since the object is a spring bean we really have no idea about how it was constructed, what parameters the constructor would take, etc… the best short term measure might just be good javadocs on BeanResourceFinder, and of course update any existing beans to set the prototype flag.
If you could open a jira for this one that would be great. Thanks.
-Justin
On Fri, Oct 15, 2010 at 4:40 AM, Martins Linde <martins.linde@anonymised.com> wrote:
Hi, mailing list,
there is problem with org.geoserver.rest.BeanResourceFinder.
Restlet resources are not designed to be thread-safe (response, request are stored in fields… ), but BeanResourceFinder method findTarget:
public Resource findTarget(Request request, Response response){
Resource res = (Resource) applicationContext.getBean(getBeanToFind());
res.init(getContext(), request, response);
return res;
}
returns the same Resource instance to concurrent threads, well, Spring returns the same instance,
workaround is to tell Spring to give different instances, that can be done with scope=“prototype” like:
But it would be nice if it could be fixed in code not in the Spring configuration file, because users may forget to add scope attribute, which may lead to real time errors.
Thank you,
Mārtiņš Linde
Download new Adobe(R) Flash(R) Builder™ 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder™ 4 (formerly
Flex(R) Builder™) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
Geoserver-devel mailing list
Geoserver-devel@anonymised.comsts.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel
–
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.
Hi Justin,
yes, You are right, it is not possible to create in code new instances of Spring managed beans. Maybe in future it would be a good idea to change restMapping route value to hold class name instead of bean references, something like this:
/x.{format}
x.className
Mārtiņš Linde
On 15 October 2010 16:55, Justin Deoliveira <jdeolive@anonymised.com…1501…> wrote:
Hi Mārtiņš,
You are correct, this is definitely a thread safety issue. I agree that it would be nicer to be able to ensure to clone the object in code rather than rely on the user to set the prototype flag. However that is easier said than done. Since the object is a spring bean we really have no idea about how it was constructed, what parameters the constructor would take, etc… the best short term measure might just be good javadocs on BeanResourceFinder, and of course update any existing beans to set the prototype flag.
If you could open a jira for this one that would be great. Thanks.
-Justin
On Fri, Oct 15, 2010 at 4:40 AM, Martins Linde <martins.linde@anonymised.com> wrote:
Hi, mailing list,
there is problem with org.geoserver.rest.BeanResourceFinder.
Restlet resources are not designed to be thread-safe (response, request are stored in fields… ), but BeanResourceFinder method findTarget:
public Resource findTarget(Request request, Response response){
Resource res = (Resource) applicationContext.getBean(getBeanToFind());
res.init(getContext(), request, response);
return res;
}
returns the same Resource instance to concurrent threads, well, Spring returns the same instance,
workaround is to tell Spring to give different instances, that can be done with scope=“prototype” like:
But it would be nice if it could be fixed in code not in the Spring configuration file, because users may forget to add scope attribute, which may lead to real time errors.
Thank you,
Mārtiņš Linde
Download new Adobe(R) Flash(R) Builder™ 4
The new Adobe(R) Flex(R) 4 and Flash(R) Builder™ 4 (formerly
Flex(R) Builder™) enable the development of rich applications that run
across multiple browsers and platforms. Download your free trials today!
http://p.sf.net/sfu/adobe-dev2dev
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel
–
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.