On Sunday, April 22, 2012 6:42:33 PM UTC+2, Sydney wrote: > > I am interested in the thread management when using request factory. I > organize my server code in a way that a business service depends on a DAO > layer that depends on an object datastore instance (object on which you can > call datastore operations - I use Twig). > > On the client side when I fire a request, the service locator creates a > new instance of the service along with its dependencies in the same Thread. > I tried to run the same request every 15 seconds. I noticed that the > service is only created once, not per request. I also noticed that after a > certain number of times, the Thread changed. This is an issue for me > because Twig requires that the object datastore must be run in the same > Thread as the one it was created. > > Is it the normal behaviour? if not what could be the reason?
It's normal that only one service instance is created (it's kept in a WeakHashMap cache though, so if you don't use it for some time, and/or you have high demands for memory, it might be garbage-collected and then recreated; but there should be only one instance per service at any given time). If you need "thread local" instances, then make a "proxy" the creates an instance per thread (probably using a ThreadLocal internally). As for the thread changing, I'm not sure where that "Datastore Thread: 29 - Current Thread: 22" line comes from, but if it's not from your log (but rather "interpolated" from there), then it's OK for the Web Server to use several threads (it might edven be mandated by the servlets spec), one per concurrent request; so the thread might change from request to request, this is the expected behavior in any servlet container. -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/G18BUHROxlMJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
